简体   繁体   中英

model binding didn't work laravel 5

I am using model binding now. But I can't catch the wildcard string.

Here is the route.php

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

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

Here is my controller method

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

When I use dd($video) in Controller. I didn't catch any data.

I already check my database. It works fine.

Did I miss something?

Your routes are probably cached. Try

php artisan route:clear

To cache them again

php artisan route:cache

尝试更改为:

public function show($video) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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