我现在正在使用模型绑定。但是我抓不到通配符字符串。
这是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) {