我現在正在使用模型綁定。但我無法捕捉通配符字符串。模型綁定不起作用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)
。我沒有收到任何數據。
我已經檢查了我的數據庫。它工作正常。
我錯過了什麼嗎?
你能告訴我們你的控制? –
您的路線是否緩存?試試'php工匠路線:清除' – andrewtweber
@ andrewtweber你是對的。我忘了這麼做。但我不能選擇你作爲答案。 – James