0
votes

After successfully login, redirect with define user role it is return an error that route not defined.

InvalidArgumentException Route [list-activity] not defined.

file path : vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUser.php

Function:

protected function authenticated(Request $request, $user)
{
    if($user->user_role=='Admin'){
        return redirect()->route('list-activity') ; // return error
    }elseif($user->role=='User'){
        return redirect()->route('front.welcome') ;
    }
}

My web.php file code

Route::get('/', function () { return view('front.welcome'); });
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::middleware(['web', 'navigation'])->group(function () {
require_once("admin/web.php");  });

Note: Added web.php file on admin folder

My routes admin\web.php file code

 Route::middleware(['auth'])->prefix('admin')->namespace('Admin')->group(function() {
 Route::get('lists-activity','ActivityController@listactivity')->name('lists-activity'); });

And here is my controller code

namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
class ActivityController extends BaseController
{
   public function listactivity() {
   dd("hello");
} }
1
try this return redirect('admin/lists-activity');Sohel0415
@Sohel0415 now return Class navigation does not exist Javed
Have you defined middleware called navigation in App\Http\Kernel? You set it Route::middleware(['web', 'navigation']) hereOhgodwhy
@Sohel0415 using a fresh copy and just create a login.what should i do ?Javed
@Javed show us your ``App\Http\Kernel`Sohel0415

1 Answers

0
votes

You're named route does not match with your route() method.

Route::get('lists-activity','ActivityController@listactivity')->name('lists-activity');

In the above code your route is named lists-activity

But in your controller, you are using

return redirect()->route('list-activity');

To fix this, you have to replace the name of the route inside your controller's method:

//return redirect()->route('list-activity');
return redirect()->route('lists-activity');