2
我已经实现路径模型,结合如下:Laravel 5.4 - 路径模型,绑定条件
路线:
Route::get('property/{property}', '[email protected]');
控制器:
public function view(Property $property)
{
$data = compact([
'property'
]);
return view('property.view', $data);
}
这个伟大的工程。不过,我想向Property模型添加一个条件来检查active = 1
。我如何以及在哪里做这件事?
你有什么试过的?你基本上是问如何使用if语句... – sisve
有没有办法在模型中做到这一点,而不是控制器? – GSTAR
该文档提到了显式绑定;这会为你工作吗? https://laravel.com/docs/5.4/routing#explicit-binding – sisve