Home  >  Q&A  >  body text

Custom function in Laravel cannot find route in resource controller

I have a checkIn function in LoginController:

The path of

LoginController.php is: Controllers/Backsite/LoginController

public function checkIn(Request $request, User $user)
{ 
   ...
}

I have defined them in web.php:

Route::group(['prefix' => 'backsite', 'as' => 'backsite.', 'middleware' => ['auth:sanctum', 'verified']], function(){
   Route::get('/login/checkIn', [LoginController::class, 'checkIn']);
});

I call them by using the following code in blade.php:

<button type="button" class="btn btn-primary btn-min-width mr-1 mb-1" href={{ route('backsite.login.checkIn') }}>CheckIn</button>
<button type="button" class="btn btn-info btn-min-width mr-1 mb-1" href={{ route('backsite.login.checkOut') }}>CheckOut</button>

But it shows an error of Route [backsite.login.checkIn] not defined.

I'm using Laravel 8 and have tried other methods found on Stackoverflow but still getting the error.

P粉904450959P粉904450959428 days ago518

reply all(1)I'll reply

  • P粉693126115

    P粉6931261152023-09-11 00:37:31

    "Undefined route error" occurs when you try to use an undefined route, please update your code and define the route in the path.

    Route::group(['prefix' => 'backsite', 'as' => 'backsite.', 'middleware' => ['auth:sanctum', 'verified']], function(){
       Route::get('/login/checkIn', [LoginController::class, 'checkIn'])->name('login.checkIn');
    });

    reply
    0
  • Cancelreply