I am tring to access the route on blade template, so I getting the error below:
Route [{$name}] not defined.
Route::patch('/update_merchant/{merchant_id}', 'MerchantsController@update')->name('update');
Blade template
<form name="merchants_data" id="merchants_data" method="post" action="{{route('update_merchant.update', [$item->merchant_id])}}">
{{ csrf_field() }}
{!! method_field('patch') !!}
Controller
public function update(Request $request, $merchant_id)
{
// Validation for required fields (and using some regex to validate our numeric value)
$request->validate([
'fees'=>'required',
]);
$merchants = Merchants_data::findorfail($merchant_id);
// Getting values from the blade template form
$merchants->fees = $request->get('fees');
$merchants->save();
return redirect('/manage_merchants')->with('success', 'Transaction Fee updated.');
}
3
Answers
It looks like you have changed the name of the route to update…
you can do one thing is go to the root of the project in your command line.. and look up
This should give you a list of all the routes you currently have in your application …
it seems your route name is "update" but you call "update_merchant.update"
As Mehran said, you named your route ‘update’ and you called ‘update_merchant.update’ in your form. When you use
That’s the name you have to use in the
You don’t put URL in the ‘route’ asset, just the name.