I am new to laravel 8 framework, I am working on controllers subfolders, but i am not able to access my Controller file. My Controller which is i am accessing is inside the Controllers/APIControllers folder with name LoginController.php path is Controllers/APIControllers/LoginController
Please help me to find best solution.
Below is my code.
api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers;
use App\Http\Controllers\APIControllers\LoginController;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('login',[LoginController::class, 'LoginPage']);
LoginController.php
<?php
use App\Http\Controllers;
use Illuminate\Http\Request;
namespace App\Http\Controllers\APIControllers;
class LoginController extends Controller
{
public function LoginPage()
{
return ["name"=>"test"];
}
}
CodePudding user response:
Inside your LoginController there is an error referring to the extended Controller class:
<?php
use App\Http\Controllers;
use Illuminate\Http\Request;
namespace App\Http\Controllers\APIControllers;
class LoginController extends Controller
{
public function LoginPage()
{
return ["name"=>"test"];
}
}
The top line referring to the Controller class should be:
<?php
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
namespace App\Http\Controllers\APIControllers;
class LoginController extends Controller
{
public function LoginPage()
{
return ["name"=>"test"];
}
}
CodePudding user response:
Add this to line in on top first of header of your LoginController
<?php
namespace App\Http\Controllers\APIControllers;
use App\Http\Controllers\Controller;
After this add other code after this make hard refresh and check.