6

I'm making a real estate application. When the user opens one of his published properties to edit, in the edit page, the form opens like this:

{!! Form::model($property, ['method'=>'PUT', 'route'=>['property.update', 'id'=>$property->id], 'files'=>true]) !!}

As you can see, in the 'route' array I'm sending the named route and the id of the property to be edited. But how do I access that $id in the Request Class?

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();
    }
}

The error I get is

Missing argument 1 for App\Http\Requests\EditPropertyRequest::authorize()

2 Answers 2

8

This is from doc

public function authorize()
{
    $commentId = $this->route('comment');

    return Comment::where('id', $commentId)
                  ->where('user_id', Auth::id())->exists();
}

So $this->route('comment'); is a URL parameter Route::post('comment/{comment}');

1
  • 1
    Ok, now I understand, you don't pass parameters but you use the route method. It worked perfect. Thanks. Sep 26, 2015 at 23:08
0
request('id')

You can use request();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.