0
votes

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:

http://localhost:8888/hrm/admin/admin/leaves/leave_review

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:

http://localhost:8888/hrm/admin/admin/leaves/leave_review

Why and how do I correct this?

Thank you

1
you've posted how you are generating your routes for consumption (routes.web) but you have not shown how you are creating the actual links to the routes (blade file probably). Your second route group is correct, you don't want the duplicate admin/admin/ (i'd imagine). Fix whatever is generating the link itself to not generate /hrm/admin/admin and you'll be gravyGiovanni S
In your view do route('leaves.leave_review') instead of admin.leaves.leave_review. And you should run php artisan route:clear after changing the route.Uzair Riaz
@GiovanniS - I rendered the view from the sidebar. And that is shown in the codemikefolu

1 Answers

0
votes

Because now your route is admin/leaves/leave_review not admin/admin/leaves/leave_review.

If you frequently change your route links you can consider using route names inside your view as route('leaves.leave_review'). this way if name is unchanged you will always get the route associated with that name.