I have a Laravel-5.8 project as shown here:
Controller: Admin/LeavesController
use App\Models\Leave;
class LeavesController extends Controller
{
public function leave_review()
{
try {
$leaves = Leave::get();
return view('admin.leaves.leave_review')
->with(['leaves', $leaves);
} catch (Exception $exception) {
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
route/web.php
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('admin/leaves/leave_review', 'LeavesController@leave_review')->name('leaves.leave_review');
});
The view folder is as this:
views->admin->leaves->leave_review.blade.php
layout/sidebar:
<li class="nav-item">
<a href="{{ route("admin.leaves.leave_review") }}" class="nav-link {{ request()->is('admin.leaves') || request()->is('admin.leaves/*') ? 'active' : '' }}">
<i class="far fa-circle nav-icon"></i>
<p>
<span>Leave-Review</span>
</p>
</a>
I have my php artisan route:list
| GET|HEAD | admin/admin/leaves/leave_review | admin.leaves.leave_review | App\Http\Controllers\Admin\LeavesController@self_review | web,auth |
When I rendered the page, though it loaded, but in the route admin is repeated twice:
That is, admin/admin
When I removed admin prefix and have the route this way:
So remove it from your route, change it to this
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin', 'middleware' => ['auth']], function () {
Route::get('leaves/leave_review', 'LeavesController@leave_review')->name('leaves.leave_review');
});
I got another error:
error 404 page not found and the uri changed to:
Why and how do I correct this?
Thank you
route('leaves.leave_review')
instead of admin.leaves.leave_review. And you should runphp artisan route:clear
after changing the route. – Uzair Riaz