簡體   English   中英

為什么Laravel路由無法按預期工作

[英]why laravel routing not working as expected

下面在我的web.php內容中

Route::get('/tripScheduler', 'trip_scheduler@index')->name('listTripSche');
Route::post('/tripScheduler/create', 'trip_scheduler@store')->name('saveTripSche');
Route::get('/tripScheduler/create', 'trip_scheduler@create');
Route::get('/tripScheduler/{sche}', 'trip_scheduler@show');

以下是我的控制器文件( trip_scheduler.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator;
use Redirect;
use DB;
use Illuminate\Support\Facades\Auth;

class trip_scheduler extends Controller
{
     public function __construct(){
        $this->middleware('auth');
    }
   public function show(trip_scheduler $sche){
        print_r($sche);
    }
}

現在,當我訪問mysite.com/tripScheduler/1 ,它應該向我顯示id為1的數據庫中的記錄。但是,它為print_r($sche)提供以下輸出

App\Http\Controllers\trip_scheduler Object (
    [middleware:protected] => Array (
        [0] => Array ( 
            [middleware] => auth 
            [options] => Array ( )
        )
    )
)

我不確定我要去哪里錯。 在此先感謝您的幫助!

您的表演功能如下:

use trip_scheduler;

    public function show(trip_scheduler $sche){
            print_r($sche);
        }

注意trip_scheduler是您的型號名稱

要么

public function show($sche){
  $rsltTrip = trip_scheduler::find($sche);
                print_r($rsltTrip);
            }

您正在鍵入提示您的控制器trip_scheduler $sche ,這就是為什么print_r顯示trip_scheduler控制器類的原因。 試試這個

class trip_scheduler extends Controller
{
     public function __construct(){
        $this->middleware('auth');
    }
   public function show($sche){
        $resp = YourModal::find($sche);
        return response($resp);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM