我现在正在使用模型绑定。但我无法捕捉通配符字符串。模型绑定不起作用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