Exception handling 错误的方法调用异常
这是我的路线Exception handling 错误的方法调用异常,exception-handling,model,laravel-5.2,Exception Handling,Model,Laravel 5.2,这是我的路线 Route::get('desktops/{desktop}','DesktopsController@getdesktop'); 这是我的控制器方法 public function getdesktop($identifier) { $desktop = Desktop::all()->where('identifier',$identifier); $casings = $desktop->casings(); dd($casings);
Route::get('desktops/{desktop}','DesktopsController@getdesktop');代码>
这是我的控制器方法
public function getdesktop($identifier)
{
$desktop = Desktop::all()->where('identifier',$identifier);
$casings = $desktop->casings();
dd($casings);
}
我已经添加了App\Desktop,下面是我在Desktop类/模型中定义的casings方法
public function casings()
{
return $this->hasMany('App\Casing');
}
现在它似乎正在处理tinker,但当我在浏览器中打开它时,它会抛出method not found的异常,确切地说是BadMethodCallException,即使我在类中定义了方法。我似乎无法解决这个问题。当您在模型中定义关系时,它作为属性而不是集合中的函数带入到雄辩对象中
因此,您需要在不使用()
的情况下访问它:
$casings=$desktop->casings代码>
您可以在中找到有关访问关系的更多信息。当您在模型中定义关系时,它将作为属性而不是集合中的函数带入到雄辩对象中
因此,您需要在不使用()
的情况下访问它:
$casings=$desktop->casings代码>
您可以在中找到有关访问关系的更多信息。我正在使用此
desktop = Desktop::all()->where('identifier',$identifier);
返回一个记录集,包含多个记录。尽管只有一张唱片,但它将其视为一个收藏。所以我试着换衣服
desktop = Desktop::all()->where('identifier',$identifier)->first();
它只为我带来了一张唱片,而且很有效。我正在使用这个
desktop = Desktop::all()->where('identifier',$identifier);
返回一个记录集,包含多个记录。尽管只有一张唱片,但它将其视为一个收藏。所以我试着换衣服
desktop = Desktop::all()->where('identifier',$identifier)->first();
这只给了我一张唱片,但效果很好。我试过,但没用,所以我自己试过,效果很好。我试过,但没用,所以我自己试过,效果很好。