PHP Snippet 1:
Route::put('customer/{customer}' , 'CustomerController@update');
PHP Snippet 2:
pulblic function update (Request $request , Customer $customer){
// validate you inputs
$validatedData = $request->validate([
// validation rules goes here
]);
// better approach would be using form requests
$customer->update($validatedData);
}
PHP Snippet 3:
Route::delete('customer/{customer} , 'CustomerController@destroy');
PHP Snippet 4:
public function destroy (Customer $customer){
$customer->delete();
}
PHP Snippet 5:
<form action="{{url("customer/{$customer->id}")}}"
method="post">
{{method_field('delete')}}
//Html Elements Here
</form>
PHP Snippet 6:
Route::resource('customer','CustomerController');
PHP Snippet 7:
Route::delete('customer/{customerId}', 'CustomerController@delete')
PHP Snippet 8:
public function delete(Request $request, $customerId)
{
$user = $request->user();
$customer= $user->customers()->find($customerId);
$customer->delete();
return back();
}
PHP Snippet 9:
Route::patch('customers/{customerId}', 'CustomerController@update')
PHP Snippet 10:
public function update(Request $request, $customerId)
{
$user = $request->user();
$customer= $user->customers()->find($customerId);
$customer->update($request->all());
return back();
}