douhu8851 2018-12-03 11:18
浏览 24

为什么laravel路由不按预期工作

Below in my web.php content

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');

Below is my controller file(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);
    }
}

Now when I visite mysite.com/tripScheduler/1, it should show me the record from database where id is 1. However, it is giving the following output for print_r($sche)

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

I am not sure where I am going wrong. Thanks in advance for your help!

  • 写回答

2条回答 默认 最新

  • dtwvr26066 2018-12-03 11:24
    关注

    Your show function like:

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

    NOTE: trip_scheduler is your model name

    OR

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

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等