1

HTML PATCHING FORM

{{ Form::model($model , [ 'route' => ['admin.friendship.update', $model->id] , 'class'=>'needs-validation ajax-form', 'method' => 'post' ]) }}
                        @method('PATCH')

   {{ Form::select('user_id' , $users , null , ['id' => 'sender', 'class' => 'form-control']) }}

   {{ Form::select('friend_id' , $users , null , ['id' => 'reciever', 'class' => 'form-control']) }}

   {{ Form::select('status' , ['-2' => -2 , '-1' => -1 , '0' => 0 , '1' => 1] , null , ['id' =>  'status', 'class' => 'form-control']) }}               
{{ Form::close() }}

Update method:

  public function update(FriendshipsAdminForm $request, Friendship $friendship)
    {
        $friendship->update($request->validated());
        return redirect()->route('admin.friendship.index');
    } 

Request form

class FriendshipsAdminForm extends FormRequest
{
  
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'user_id'  => 'required',
            'friend_id'  => 'required',
            'status'  => 'required',
        ];
    }
}

Route:

Route::resource('friendship', \App\Http\Controllers\Admin\FriendshipController::class);

This is my form and it's really strange. maybe I can not see a thing that is blocking me from doing this. there is not typo or syntax mistake. Is there anything about patch method I should consider even when trying update method?

UPDATE

enter image description here

ERROR MESSAGE , ERROR STATUS 405

UPDATE2 I'm using ajax for it.

I'm using ajax the way I use above with near 30 models and all are more complex than this one but all are updating and working nicely but this one is strange

5
  • can you write error message? Commented May 4, 2021 at 12:14
  • Did you get a server error or an application-level error? Commented May 4, 2021 at 13:17
  • just updated right now Commented May 4, 2021 at 13:42
  • Does this answer your question? How to use patch request in Laravel? Commented May 4, 2021 at 13:46
  • @ponsfrilus read update2 Commented May 4, 2021 at 13:52

1 Answer 1

2

Since you using ajax, @method is not working in that. You need to activate PATCH in your webserver, or change your ajax code to submit form in post and add _method in params. For example in jQuery

$.ajax({
   ...
   method: 'POST',
   data:{
        ...
        '_method': 'PATCH',
   }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.