1

I'm using Laravel v8 and i tried to create an API route for admin authentication like this:

routes/api.php

Route::prefix('/admin')->name('admin.')->namespace('Admin')->group(function(){
    Route::middleware('auth:admin-api')->group( function () {
        Route::resource('tasks', TaskController::class);
    });
    Route::namespace('Auth')->group(function(){
        //Login Routes
        Route::post('/login','LoginController@login'); 
        Route::post('/register','LoginController@register'); 
    });
});

when i tried to access http://laravel.local/api/admin/login i got this following error:

Illuminate\Contracts\Container\BindingResolutionException: Target class [Admin\Auth\LoginController] does not exist. in file /Users/John/Sites/laravel/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 875

I already created the controller file in app/Http/Controllers/API/Admin/Auth/LoginController.php

namespace App\Http\Controllers\API\Admin\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\API\BaseController as BaseController;
use App\Models\Admin;
use Validator;

   
class LoginController extends BaseController
{

    public function login(Request $request)
    {
      ....
    }
}
1

2 Answers 2

0

You created LoginController in App\Http\Controllers\API\Admin\Auth namespace, but when you added route login in api route file, don't use the API namespace.

Sign up to request clarification or add additional context in comments.

Comments

0

You should update you code.

use App\Http\Controllers\API\Admin\Auth\LoginController;

Route::prefix('/admin')->name('admin.')->group(function(){
    Route::middleware('auth:admin-api')->group( function () {
        Route::resource('tasks', TaskController::class);
    });
 
    Route::post('/login',  [LoginController::class, 'login']); 
    Route::post('/register',  [LoginController::class, 'register']); 
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.