Jua*_*ett 6 php request laravel
我正在申请房地产。当用户打开他发布的属性之一进行编辑时,在编辑页面中,表单打开如下:
{!! Form::model($property, ['method'=>'PUT', 'route'=>['property.update', 'id'=>$property->id], 'files'=>true]) !!}
Run Code Online (Sandbox Code Playgroud)
如您所见,在 '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();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
缺少 App\Http\Requests\EditPropertyRequest::authorize() 的参数 1
这是来自文档
public function authorize()
{
$commentId = $this->route('comment');
return Comment::where('id', $commentId)
->where('user_id', Auth::id())->exists();
}
Run Code Online (Sandbox Code Playgroud)
所以$this->route('comment');
是一个URL参数Route::post('comment/{comment}');
归档时间: |
|
查看次数: |
1835 次 |
最近记录: |