Php laravel将多个变量传递到控制器视图

Php laravel将多个变量传递到控制器视图,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在尝试获取url,例如localhost/cat/restaurants/this-is-a-test,但在尝试加载url时,它会抛出一个错误 我有两个db表“评论”和“类别” 评论-id,cat_id,slug,类别-id,cat 我有一个模型,它通过cat_id链接两个表 SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“cat”(SQL:select*from reviews,其中cat=Restaurants,slug=this-is-a-test) 我

我正在尝试获取url,例如localhost/cat/restaurants/this-is-a-test,但在尝试加载url时,它会抛出一个错误

我有两个db表“评论”和“类别”

评论-id,cat_id,slug,类别-id,cat

我有一个模型,它通过cat_id链接两个表

SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“cat”(SQL:select*from reviews,其中cat=Restaurants,slug=this-is-a-test)

我猜它试图从评论表中提取“cat”而不是“categorys”,但是在我的刀片模板中,我有一个url路由-{!!url::route('reviews.slug',[$review->categorys->cat,$review->slug]),它提取两个变量并加载url localhost/cat/restaurants/this-is-a-test

routes.php

Route::get('reviews/cat/{cat}/{slug}', ['as' => 'reviews.slug', 'uses' => 'ReviewController@ShowbySlug']); 
reviewcontroller.php

public function ShowBySlug($cat,$slug) {
$slugs = Review::with('reviewimages','maps','categorys')->where('cat',   $cat)->where('slug', $slug)
         ->get();
return View::make('pages.reviews')
       ->with('slugs', $slugs)
       ->with('cat', $cat)
       ;

}

您可以使用
whereHas
按关系过滤:

$slugs = Review::with('reviewimages','maps','categorys')
     ->whereHas('categorys', function($q) use ($cat){
         $q->where('cat', $cat);
     })
     ->where('slug', $slug)
     ->get();