我正在制作一个房地产应用程序。当用户打开其中一条已发布的房产进行编辑时,在编辑页面,表单会像这样打开:
{!! Form::model($property, ['method'=>'PUT', 'route'=>['property.update', 'id'=>$property->id], 'files'=>true]) !!}
正如您所见,在“route”数组中,我正在发送命名路由和要编辑的属性的id。但是,我如何在请求类中访问该$id?
class EditPropertyRequest extends Request
{
/**
* Determine if the user owns this property and is authorized to make this request.
*
* @return bool
*/
public function authorize($id)
{
return Property::where('user_id', auth()->user()->id)
->where('id', $id)
->exists();
}
}
我得到的错误是
缺少参数 1 用于 App\Http\Requests\EditPropertyRequest::authorize()