繁体   English   中英

模型绑定不起作用 Laravel 5

[英]model binding didn't work laravel 5

我现在正在使用模型绑定。 但我无法捕捉通配符字符串。

这是route.php

Route::bind('video', function($video) {
    return App\Video::where('videoID', $video)->first();
});

Route::get('/result/{video}', 'IndexController@show');

这是我的控制器方法

public function show(Video $video) {
    $video_tag = Video_tag::where( 'id', $video->id )->get(['id', 'tag', 'time']);
    $count = array();
    foreach ( $video_tag as $tag ) {
        $num = Video_tag::where(['id' => $video->id, 'tag' => $tag->tag])->get()->count();
        array_push($count, $num);
    }

    $forJs = array();
    $hasAdded = false ;
    $size = count($video_tag);
    foreach ( $video_tag as $k=>$tag ) {
        if ( !$hasAdded ) {
            $add = array( $count[$k] => $tag );
            $hasAdded = true;
        }
            array_push($forJs, $add);
        if ( $size-1 > $k && strcmp($video_tag[$k]->tag, $video_tag[$k+1]->tag) != 0 )
            $hasAdded = false;
    }

    return view('viewVideo', compact('video', 'video_tag', 'count', 'forJs'));
}

当我在控制器中使用dd($video)时。 我没有捕捉到任何数据。

我已经检查了我的数据库。 它工作正常。

我错过了什么?

您的路线可能已缓存。 尝试

php artisan route:clear

再次缓存它们

php artisan route:cache

尝试更改为:

public function show($video) {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM