@josh__gikundiro Can you please add your controller code here?
Target class [] does not exist issue!
I am facing the same problem. I had been accessing my routes well till I received the error stating "Target class [Controller] does not exist." I am using laravel 10.18.0
I can't even return any view.... May somebody help please ??
I have two controllers these are for the Controller.php
@josh__gikundiro Is your home route controller within any folder?
@DhPandya no the directory structure is the same i.e. app\http\controller where I have inside that folder the Controller.php and RegisterController.php which I am trying to access in my route web.php file
@josh__gikundiro Can you show your route file web.php from where you are calling controller. Make sure you have imported the controller properly
@josh__gikundiro every post includes a link to the formatting guide.
You may use Markdown with GitHub-flavored code blocks.
put three backticks ``` on their own line before and after the code block
@Snapey this my Controller.php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
}
Secondary this is my RegisterController which I am trying to call through route web.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Register;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Requests;
use Illuminate\Routing\Controller as BaseController;
class RegisterController extends Controller
{
public function store(Request $request){
$data= $request->validate([
'fullName'=>'string|max:255',
'username'=> 'string|max:255',
'address'=> 'string|max:255',
'email'=> 'email|unique:users',
'password'=>'string|min:8',
'profilePicture'=> 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
]);
$register= new Register();
$register->fullName= $request->input('fullName');
$register->userName= $request->input('userName');
$register->email= $request->input('email');
$register->address= $request->input('address');
$register->phoneNumber= $request->input('phoneNumber');
// profile picture
if ($request->hasFile('profilePicture')) {
$imagePath = $request->file('profilePicture')->store('profile_pictures', 'public');
$data['profilePicture'] = $imagePath;
}
// password
$data['password'] = Hash::make($data['password']);
$user =User::create($data);
return redirect()->route('login')->with('success', 'Registration successful! Please log in.');
// $register->role= $request->input('role');
// $register-> save();
// return redirect('/login')->back()->with('success','Registered successfully');
}
public function show(Register $register)
{
//
}
public function edit(Register $register)
{
//
}
public function update(Request $request, Register $register)
{
//
}
public function destroy(Register $register)
{
//
}
public function login(Request $request){
$uname= $request->input('userName');
$pwd=$request->input('password');
$user=DB::table('registers')->where('userName',$uname)->where('password',$pwd)->get();
if (!isset($user[0])) {
// abort(404, 'The requested array key does not exist.');
return redirect('/login')->with('danger', 'Invalid Credentials');
}
if($user[0] -> password == $pwd){
$request->session()->put('user', $request->input('userName'));
return redirect('/dash')->with('welcome', 'Happy day!');
}else{
return redirect('/login')->with('danger', 'Invalid Credentials');
}
}
}
and this is my web.php file
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RegisterController;
Route::view('admin','admin');
Route::view('/','index');
Route::view('signup','signup');
Route::view('login','login');
Route::post('/register','RegisterController@store');
Route::view('boot', 'boot');
?>
Thanks for the help ...
@josh__gikundiro If you are using Laravel 10, the syntax should be
Route::post('/register', [RegisterController::class, 'store']);
Delete this code right away
$user=DB::table('registers')->where('userName',$uname)->where('password',$pwd)->get();
Plain text passwords? Get out of here, we don't tolerate that type of behaviour.
Why reinvent login when Laravel comes with authentication baked in. Its tried, tested and secure.
@Snapey let me check the authentication please...
@josh__gikundiro Even the below imports are useless on the top of your RegisterController .
use Illuminate\Routing\Controller as BaseController;
use App\Http\Controllers\Controller;
@snapey @dhpandya I don't mind the controller with that plain text password within function, the issue is that , I am trying to access my index page through my web.php file and I get the error Target class [Controller] does not exist. I showed my controllers to either review them whether they have something to do with it, or accessing whether there is a syntax error or something.
Again this is my route web.php file
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RegisterController;
Route::view('admin','admin');
Route::get('/', function () {
return view('index');
});
Route::view('signup','signup');
Route::view('login','login');
Route::post('/register','RegisterController@store');
Route::view('boot', 'boot');
?>
If I try to access signup or login or boot it works but I can't access my index page.
@Snapey I think you answered about /register end point. I need to access my index file which is the landing page of my project, which as you can see in the web.php has get function to return the index page but It is returning the same error Target class [Controller] does not exist. I don't know if my question is clear Sir.
@josh__gikundiro show more of the error
@josh__gikundiro Could you please also add your index.blade.php here?
@josh__gikundiro please take the free laravel from scratch training and learn the basics (especially security). Just my suggestion.
Please or to participate in this conversation.