0

i want to update a customer using patch methodn here is my route

Route::patch('/customers/updateCustomer', 'CustomerController@update')
    ->name('customers.update');

and here is my form :

<form method="POST" action="{{ route('customers.update') }}">
    @csrf
    @method('PATCH')

how to pass the id of the customer , the update method requires two parameters, when the first one is the data from the from , the second should be the id of the customer

1
  • add it to your route by separating it with a comma. try this: <form method="POST" action="{{ route('customers.update',$customer->id) }}"> Commented Jun 15, 2020 at 10:25

3 Answers 3

1

You should send the customer id with the route() helper function.

Make sure to send the customer object during the form rendering.

<form method="POST" action="{{ route('customers.update', $customer['id']) }}">
    @csrf
    @method('PATCH')

And modify the route slightly.

Route::patch('/customers/updateCustomer/{customerId}', 'CustomerController@update')->name('customers.update');
Sign up to request clarification or add additional context in comments.

Comments

1

add customer id to the route like

Route::patch('/customers/updateCustomer/{id}', 'CustomerController@update')->name('customers.update');

and then your form action should be like

<form method="POST" action="{{ route('customers.update',$customer->id) }}">

you have to send the customer object from where you are returning to the form. and finally your update function

public function update(Request $request, $id)
    {
        //your things to do
    }

Comments

1

You have to use like this

<form method="POST" action="{{ route('customers.update',['id'=>$customer->id]) }}">

And your route should be

Route::patch('/customers/updateCustomer/{id}', 'CustomerController@update')->name('customers.update');

And your controller should be

public function update(Request $request, $id){

    //your code

}

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.