I have this code in my controller.
public function courierUpdate(Request $request, $id)
{
$request->validate([
'current_location' => 'required',
]);
$courierInfoUpdate =CourierInfo::findOrFail($id);
$courierInfoUpdate->current_location = $request->current_location;
$courierInfoUpdate->save();
$notify[] = ['success', 'Courier location info has been updated'];
return back()->withNotify($notify);
}
I have form that would be used to update the shipping details;
<div >
<div >
<div >
<h5 >@lang('Courier Location')</h5>
<div >
<form action="{{route('courier.Update')}}" method="POST">
@csrf
<div >
<div >
<label for="current_location" >@lang('Current Location')</label>
<input type="text" name="current_location" value="{{__($courierInfo->current_location)}}" required="">
</div>
</div>
<div >
<button type="submit" ><i ></i>@lang('Update')</button>
</div>
</form>
</div>
</div>
</div>
</div>
I have also added the route in web.php
Route::post('/courier-Update','App\Http\Controllers\CourierSettingController@courierUpdate')->name('courier.Update');
But I get this eror when I run the page;
Route [courier.Update] not defined. (View: /home/somename/example.com/core/resources/views/admin/courier/details.blade.php)
When have cleared the route cache;
Route::get('/clear', function(){
\Illuminate\Support\Facades\Artisan::call('optimize:clear');
});
But i still get the error message;
When I check the generated route paths using this code;
Route::get('routes', function () {
$routeCollection = Route::getRoutes();
echo "<table style='width:100%'>";
echo "<tr>";
echo "<td width='10%'><h4>HTTP Method</h4></td>";
echo "<td width='10%'><h4>Route</h4></td>";
echo "<td width='10%'><h4>Name</h4></td>";
echo "<td width='70%'><h4>Corresponding Action</h4></td>";
echo "</tr>";
foreach ($routeCollection as $value) {
echo "<tr>";
echo "<td>" . $value->methods()[0] . "</td>";
echo "<td>" . $value->uri() . "</td>";
echo "<td>" . $value->getName() . "</td>";
echo "<td>" . $value->getActionName() . "</td>";
echo "</tr>";
}
echo "</table>";
});
I get thisline indictating that the that route exist;
POST admin/courier-Update admin.courier.Update App\Http\Controllers\Admin\App\Http\Controllers\CourierSettingController@courierUpdate
What could be the problem?
CodePudding user response:
You should replace
route('courier.Update')
with
route('admin.courier.Update')
Since that's the full name of your route.
You probably declared your route inside a route group that adds the admin.
prefix to the name of your route.
CodePudding user response:
I think you have to use modern way to establish routes in laravel.
If you have the laravel post 8th version, then the routing must be like Route::get('/user', [UserController::class, 'index']); More information you could find here: https://laravel.com/docs/9.x/routing