2015-12-08 188 views
2

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

这里是route.php

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

Route::get('/result/{video}', '[email protected]'); 

这里是我的控制器方法

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)。我没有收到任何数据。

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

我错过了什么吗?

+0

你能告诉我们你的控制? –

+0

您的路线是否缓存?试试'php工匠路线:清除' – andrewtweber

+0

@ andrewtweber你是对的。我忘了这么做。但我不能选择你作为答案。 – James

回答

1

你的路线很可能缓存。尝试

php artisan route:clear 

要再次缓存它们

php artisan route:cache 
0

尝试更改为此:

public function show($video) { 
+0

使用此我可以捕获字符串,但模型绑定不起作用。 – James