Method App\Http\Controllers\ProductController::getIndex()() does not exist - laravel

web.php file
this is my web.php file using laravel 5.4
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', [
'uses' =>'ProductController#getIndex()',
'as' =>'product.index'
]);
ProductController.php
this is my controller file using laravel5.4
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProductController extends Controller
{
//
public function getIndex(){
return view('shop.index');
}
}
How to get rid of this error please help me.
What's wrong with it ?

You shouldn't use () in your route definition. It should be:
Route::get('/', [
'uses' =>'ProductController#getIndex',
'as' =>'product.index'
]);

Related

Target class [App\Http\Controllers\Auth\LoginController] does not exist

I am using Laravel9, trying to seperate frontend and backend. I did many replace, like app\Http change to be app\Frontend\Http or app\Backend\Http.
I did the separation before, it worked. Now I cannot login or logout. But welcome page is ok. Maybe this is because the routes file ?
Auth::routes();
All content of routes/web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::group(
[
'prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ],
], function()
{
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Frontend\Http\Controllers\HomeController::class, 'index'])->name('home');
});
I also did:
composer dump-autoload
php artisan clear-compiled
php artisan route:clear
php artisan cache:clear
not working.
LoginController
<?php
namespace App\Frontend\Http\Controllers\Auth;
use App\Frontend\Http\Controllers\Controller;
use App\Frontend\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
...
Auth routes of laravel/ui package is kinda hardcoded within AuthRouteMethods class. This is the part of its method from Github repository
$namespace = class_exists($this->prependGroupNamespace('Auth\LoginController')) ? null : 'App\Http\Controllers';
$this->group(['namespace' => $namespace], function() use($options) {
// Login Routes...
if ($options['login'] ?? true) {
$this->get('login', 'Auth\LoginController#showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController#login');
}
// more code
It ensure that Auth routes will be under "default" namespace of Theme\Http\Controllers. But you may change it if wrap it in a group like
Route::group(['namespace' => 'App\Frontend\Http\Controllers'], function () {
Auth::routes();
});
This way you'll prepend group namespace to it so package will find App\Frontend\Http\Controllers\Auth\LoginController class and so on for every other auth controller
Note 1 - all controllers should be under Auth namespace and named specifically as defined in a package, you cannot change it to be like App\Whatever\LoginController or Auth\Whatever\Auth\MyLoginController - but you can do it with App\Whatever\Auth\LoginController
Note 2 - this wouldn't work with uncommented protected $namespace = 'App\\Http\\Controllers'; property within RouteServiceProvider class, as it will prepend namespace twice (you will get something like App\Http\Controllers\App\Frontend\Http\Controllers\Auth\LoginController)

Laravel Seperate folders for Web and API Controllers causing error

Im currently trying to create an API for my laravel project,
I have decided to move my API controllers into a subfolder of Controllers. This is the folder structure:
This is the routes file for the api:
<?php
use Illuminate\Http\Request;
use app\Http\Controllers\APIControllers;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group(['prefix' => 'v1'], function() {
Route::get('/event_locations', 'EventLocationsAPIController#all');
});
And this is the EventLocationsAPIController:
<?php
namespace App\Http\Controllers\APIControllers;
use App\EventLocation;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class EventLocationAPIController extends Controller
{
public function all()
{
$locations = EventLocation::all();
return response()->json($locations);
}
}
When I send an GET request to /api/v1/event_locations I get the following error
Target class [App\Http\Controllers\EventLocationsAPIController] does not exist.
Any help would be appreciated!
You need to declare the namespace in route group as well.
Route::group(['prefix' => 'v1','namespace'=>'APIControllers'], function() {
Route::get('/event_locations', 'EventLocationAPIController#all');
});
you have given EventLocations plural and the controller name is singular EventLocation change the name of the controller as EventLocationAPIController in the route file.
You have to declare your nameaspace on router's group like this:
Route::namespace('APIControllers')->group(function () {
// Controllers Within The "App\Http\Controllers\APIControllers" Namespace
Route::group(['prefix' => 'v1'], function() {
Route::get('/event_locations', 'EventLocationAPIController#all');
});
});
Check Laravel docs for more info.

Controller action is not available

I am not familiar with laravel but from what I red I made this:
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ChatController extends Controller
{
public function index(Request $request)
{
var_dump(123123);die;
if (!Auth::check()) {
return redirect('/');
}
return 1;
}
}
Now I am trying to request it like domain.com/open-chat. And my web.php configuration about it is:
Route::get('/open-chat', 'ChatController#index');
But I am getting redirected to the home page. I`ve checked the middleware controllers if some of it redirects me but no. The other controllers ( which were already made when I came ) works fine. What am I missing ?
EDIT
web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/clear-cache', function() {
Artisan::call('cache:clear');
return "Cache is cleared";
});
Route::get('/config-cache', function() {
Artisan::call('config:cache');
return "Config is cleared";
});
Route::get('/view', function() {
Artisan::call('view:clear');
return "View is cleared";
});
/* Route::get('/', function () {
return view('welcome');
}); */
Route::group(['prefix' => 'siteadmin', 'namespace' => 'Admin'], function () {
Route::get('/', 'Auth\LoginController#showLoginForm');
Route::post('login', 'Auth\LoginController#login')->name('admin.login');
Route::post('logout', 'Auth\LoginController#logout')->name('admin.logout');
});
Route::group(['prefix'=>'siteadmin', 'namespace' => 'Admin','middleware' => 'auth'], function () {
Route::get('/dashboard', 'DashboardController#index')->name('dashboard.index');
Route::get('/edit-profile', 'CommonController#editProfile');
Route::post('/updateprofile', 'CommonController#updateprofile');
/**
Routes for site settings
**/
Route::get('/site-settings', 'SiteSettingController#index')->name('sitesettings.index');
Route::post('/site-settings/store', 'SiteSettingController#store')->name('sitesettings.save');
Route::get('/subject-categories', 'SubjectCategoriesController#index')->name('subject-categories.index');
Route::get('/subject-categories/create', 'SubjectCategoriesController#create')->name('subject-categories.create');
Route::post('/subject-categories/store', 'SubjectCategoriesController#store')->name('subject-categories.store');
Route::get('/subject-categories/edit/{id}', 'SubjectCategoriesController#edit')->name('subject-categories.edit');
Route::post('/subject-categories/update/{id}', 'SubjectCategoriesController#update')->name('subject-categories.update');
Route::get('/subject-categories/drop/{id}', 'SubjectCategoriesController#drop')->name('subject-categories.drop');
Route::post('/subject-categories/delete-image/{id}', 'SubjectCategoriesController#deleteImage');
/**
Routes for teachers users
**/
Route::get('/users/teachers', ['middleware'=>'auth','uses'=>'UserController#getTeachersList'])->name('teachers.index');
Route::get('/users/teachers/create', ['middleware'=>'auth','uses'=>'UserController#createTeacher'])->name('teachers.create');
Route::post('/users/teachers/save', ['middleware'=>'auth','uses'=>'UserController#saveTeacher'])->name('teachers.save');
Route::get('/users/teachers/edit/{id}', ['middleware'=>'auth','uses'=>'UserController#editTeacher'])->name('teachers.edit');
Route::get('/users/teachers/show/{id}', ['middleware'=>'auth','uses'=>'UserController#showTeacher'])->name('teachers.show');
Route::post('/users/teachers/update/{id}', ['middleware'=>'auth','uses'=>'UserController#updateTeacher'])->name('teachers.update');
Route::get('/users/teachers/delete/{id}', ['middleware'=>'auth','uses'=>'UserController#deleteTeacher']);
Route::get('/users/teachers/change-status/{id}', ['middleware'=>'auth','uses'=>'UserController#changeTeacherStatus']);
Route::post('/users/get-cities-by-country', ['middleware'=>'auth','uses'=>'UserController#getCitiesByCountry']);
Route::get('/users/teachers/messages/{id}', ['middleware'=>'auth','uses'=>'UserController#getTeacherMessageThreads'])->name('teachers.messages');
Route::get('/users/teachers/view-message/{id}', ['middleware'=>'auth','uses'=>'UserController#getAllMessagesByThreadID'])->name('teacher.view-message');
Route::post('/users/teachers/delete-profile-image/{id}', ['middleware'=>'auth','uses'=>'UserController#deleteTeacherProfileImage']);
/**
Routes for driver users
**/
Route::get('/users/students', ['middleware'=>'auth','uses'=>'UserController#getStudentsList'])->name('students.index');
Route::get('/users/students/create', ['middleware'=>'auth','uses'=>'UserController#createStudent'])->name('students.create');
Route::post('/users/students/save', ['middleware'=>'auth','uses'=>'UserController#saveStudent'])->name('students.save');
Route::get('/users/students/edit/{id}', ['middleware'=>'auth','uses'=>'UserController#editStudent'])->name('students.edit');
Route::get('/users/students/show/{id}', ['middleware'=>'auth','uses'=>'UserController#showStudent'])->name('students.show');
Route::post('/users/students/update/{id}', ['middleware'=>'auth','uses'=>'UserController#updateStudent'])->name('students.update');
Route::get('/users/students/delete/{id}', ['middleware'=>'auth','uses'=>'UserController#deleteStudent']);
Route::get('/users/students/change-status/{id}', ['middleware'=>'auth','uses'=>'UserController#changeStudentStatus']);
/**
Routes for countries
**/
Route::get('/countries', ['middleware'=>'auth','uses'=>'CountryController#index'])->name('countries.index');
Route::get('/countries/create', ['middleware'=>'auth','uses'=>'CountryController#create'])->name('countries.create');
Route::post('/countries/save', ['middleware'=>'auth','uses'=>'CountryController#store'])->name('countries.save');
Route::get('/countries/edit/{id}', ['middleware'=>'auth','uses'=>'CountryController#edit'])->name('countries.edit');
Route::get('/countries/show/{id}', ['middleware'=>'auth','uses'=>'CountryController#show'])->name('countries.show');
Route::post('/countries/update/{id}', ['middleware'=>'auth','uses'=>'CountryController#update'])->name('countries.update');
Route::get('/countries/delete/{id}', ['middleware'=>'auth','uses'=>'CountryController#destroy']);
Route::get('/countries/change-status/{id}', ['middleware'=>'auth','uses'=>'CountryController#changeStatus']);
Route::post('/countries/delete-image/{id}', ['middleware'=>'auth','uses'=>'CountryController#deleteImage']);
/**
Routes for cities
**/
Route::get('/cities', ['middleware'=>'auth','uses'=>'CityController#index'])->name('cities.index');
Route::get('/cities/create', ['middleware'=>'auth','uses'=>'CityController#create'])->name('cities.create');
Route::post('/cities/save', ['middleware'=>'auth','uses'=>'CityController#store'])->name('cities.save');
Route::get('/cities/edit/{id}', ['middleware'=>'auth','uses'=>'CityController#edit'])->name('cities.edit');
Route::get('/cities/show/{id}', ['middleware'=>'auth','uses'=>'CityController#show'])->name('cities.show');
Route::post('/cities/update/{id}', ['middleware'=>'auth','uses'=>'CityController#update'])->name('cities.update');
Route::get('/cities/delete/{id}', ['middleware'=>'auth','uses'=>'CityController#destroy']);
Route::get('/cities/change-status/{id}', ['middleware'=>'auth','uses'=>'CityController#changeStatus']);
Route::post('/cities/delete-image/{id}', ['middleware'=>'auth','uses'=>'CityController#deleteImage']);
/**
Routes for subjects
**/
Route::get('/subjects', ['middleware'=>'auth','uses'=>'SubjectController#index'])->name('subjects.index');
Route::get('/subjects/create', ['middleware'=>'auth','uses'=>'SubjectController#create'])->name('subjects.create');
Route::post('/subjects/save', ['middleware'=>'auth','uses'=>'SubjectController#store'])->name('subjects.save');
Route::get('/subjects/edit/{id}', ['middleware'=>'auth','uses'=>'SubjectController#edit'])->name('subjects.edit');
Route::get('/subjects/show/{id}', ['middleware'=>'auth','uses'=>'SubjectController#show'])->name('subjects.show');
Route::post('/subjects/update/{id}', ['middleware'=>'auth','uses'=>'SubjectController#update'])->name('subjects.update');
Route::get('/subjects/delete/{id}', ['middleware'=>'auth','uses'=>'SubjectController#destroy']);
Route::get('/subjects/change-status/{id}', ['middleware'=>'auth','uses'=>'SubjectController#changeStatus']);
/**
Routes for classes
**/
Route::get('/classes', ['middleware'=>'auth','uses'=>'ClassController#index'])->name('classes.index');
Route::get('/classes/create', ['middleware'=>'auth','uses'=>'ClassController#create'])->name('classes.create');
Route::post('/classes/save', ['middleware'=>'auth','uses'=>'ClassController#store'])->name('classes.save');
Route::get('/classes/edit/{id}', ['middleware'=>'auth','uses'=>'ClassController#edit'])->name('classes.edit');
Route::get('/classes/show/{id}', ['middleware'=>'auth','uses'=>'ClassController#show'])->name('classes.show');
Route::post('/classes/update/{id}', ['middleware'=>'auth','uses'=>'ClassController#update'])->name('classes.update');
Route::get('/classes/delete/{id}', ['middleware'=>'auth','uses'=>'ClassController#destroy']);
Route::get('/classes/change-status/{id}', ['middleware'=>'auth','uses'=>'ClassController#changeStatus']);
Route::post('/classes/get-subjects-by-category', ['middleware'=>'auth','uses'=>'ClassController#getSubjectsByCategory']);
/**
Routes for sliders
**/
Route::get('/sliders', 'SliderController#index')->name('sliders.index');
Route::get('/sliders/create', 'SliderController#create')->name('sliders.create');
Route::post('/sliders/store', 'SliderController#store')->name('sliders.save');
Route::get('/sliders/edit/{id}', 'SliderController#edit')->name('sliders.edit');
Route::post('/sliders/update/{id}', 'SliderController#update')->name('sliders.update');
Route::get('/sliders/delete/{id}', 'SliderController#destroy')->name('sliders.delete');
Route::get('/sliders/change-status/{id}', ['middleware'=>'auth','uses'=>'SliderController#changeStatus']);
Route::post('/sliders/delete-image/{id}', 'SliderController#deleteImage');
/**
Routes for teacher classes
**/
Route::get('/teacher-classes', 'TeacherClassController#index')->name('teacher-classes.index');
Route::get('/teacher-classes/create', 'TeacherClassController#create')->name('teacher-classes.create');
Route::post('/teacher-classes/store', 'TeacherClassController#store')->name('teacher-classes.save');
Route::get('/teacher-classes/edit/{id}', 'TeacherClassController#edit')->name('teacher-classes.edit');
Route::post('/teacher-classes/update/{id}', 'TeacherClassController#update')->name('teacher-classes.update');
Route::get('/teacher-classes/delete/{id}', 'TeacherClassController#destroy')->name('teacher-classes.delete');
Route::post('/teacher-classes/get-subjects-by-category', 'TeacherClassController#getSubjectsByCategory');
Route::post('/teacher-classes/get-classes-by-category-and-subject', 'TeacherClassController#getClassesBySubjectAndCategory');
/**
Routes for orders
**/
Route::get('/orders', 'OrderController#index')->name('orders.index');
Route::get('/orders/show/{id}', 'OrderController#show')->name('orders.show');
Route::get('/orders/export-orders', 'OrderController#exportOrders')->name('orders.export-orders');
/**
Routes for bookings
**/
Route::get('/bookings', 'BookingController#index')->name('bookings.index');
Route::get('/bookings/teacher-bookings/{teacher_id}', 'BookingController#getTeacherAllBookings')->name('bookings.bookings');
Route::get('/bookings/show/{id}', 'BookingController#show')->name('bookings.show');
Route::get('/bookings/export-teacher-bookings/{teacher_id}', 'BookingController#exportTeacherBookings')->name('bookings.export-teacher-bookings');
/**
Routes for bookings
**/
Route::get('/messages', 'MessageController#index')->name('messages.index');
Route::get('/messages/show/{id}', 'MessageController#show')->name('messages.show');
/**
Routes for reviews
**/
Route::get('/reviews', 'ReviewController#index')->name('reviews.index');
Route::get('/reviews/show/{id}', 'ReviewController#show')->name('reviews.show');
/**
Routes for blogs
**/
Route::get('/blogs', 'BlogController#index')->name('blogs.index');
Route::get('/blogs/create', 'BlogController#create')->name('blogs.create');
Route::post('/blogs/store', 'BlogController#store')->name('blogs.save');
Route::get('/blogs/edit/{id}', 'BlogController#edit')->name('blogs.edit');
Route::post('/blogs/update/{id}', 'BlogController#update')->name('blogs.update');
Route::get('/blogs/delete/{id}', 'BlogController#destroy')->name('blogs.delete');
Route::get('/blogs/change-status/{id}', ['middleware'=>'auth','uses'=>'BlogController#changeStatus']);
Route::post('/blogs/delete-image/{id}', 'BlogController#deleteImage');
});
Auth::routes();
Route::get('{locale?}', 'HomeController#index');
Route::get('/en', 'HomeController#index');
Route::get('/open-chat', 'ChatController#index');
Route::get('/ar', 'HomeController#index');
Route::get('/home', 'HomeController#index')->name('home');
Route::post('/get-cities-by-country', 'SearchController#getCitiesByCountry');
Route::post('/get-subjects-by-category', 'SearchController#getSubjectsByCategory');
Route::post('/register', 'CommonController#register');
Route::post('/login', 'CommonController#login');
Route::post('/forgot-password', 'CommonController#forgotPassword');
Route::get('/{locale?}/reset-password/{token}', 'CommonController#resetPassword');
Route::post('/{locale?}/resetpassword', 'CommonController#resetNewPassword')->name('reset-pass');
Route::get('/{locale?}/classes/search', 'ClassController#searchClasses')->name('search');
Route::get('/{locale?}/classes/all-cities', 'ClassController#getAllCitiesClasses');
Route::get('/{locale?}/classes/{type}/{id}', 'ClassController#getClassesByType');
Route::get('/{locale?}/view-class/{id}', 'ClassController#viewTeacherClassDetails')->name('view-class');
Route::get('/{locale?}/finish-class/{id}', 'ClassController#finishTeacherClass')->name('finish-class');
Route::post('/create-booking', 'CommonController#createBooking');
Route::post('/{locale?}/submit-review', 'CommonController#submitReview');
Route::get('/{locale?}/blogs', 'HomeController#getAllBlogs')->name('blogs');
Route::get('/{locale?}/blogs/{slug}', 'HomeController#getBlogDetails')->name('blogs.detail');
Route::get('/paypal/checkout/{order}/completed', [
'name' => 'PayPal Express Checkout',
'as' => 'paypal.checkout.completed',
'uses' => 'User\BookingController#completed',
]);
Route::get('/paypal/checkout/{order}/cancelled', [
'name' => 'PayPal Express Checkout',
'as' => 'paypal.checkout.cancelled',
'uses' => 'User\BookingController#cancelled',
]);
Route::post('/webhook/paypal/{order?}/{env?}', [
'name' => 'PayPal Express IPN',
'as' => 'webhook.paypal.ipn',
'uses' => 'User\BookingController#webhook',
]);
/**
User dashboard routes start
**/
Route::group(['prefix'=>'{locale?}/user', 'namespace' => 'User','middleware' => 'auth'], function () {
Route::get('/dashboard', 'DashboardController#index')->name('user.dashboard');
Route::get('/edit-profile', ['uses'=>'ProfileController#editProfile'])->name('user.edit-profile');
Route::post('/update-profile/{id}', ['uses'=>'ProfileController#updateProfile'])->name('user.update-profile');
Route::post('/update-image/{id}', ['uses'=>'ProfileController#updateUserImage'])->name('user.update-image');
Route::get('/change-password', ['uses'=>'ProfileController#changePassword'])->name('user.change-password');
Route::post('/update-password', ['uses'=>'ProfileController#updatePassword'])->name('user.update-password');
Route::get('/my-classes', ['uses'=>'ClassController#getTeacherClasses'])->name('user.my-classes');
Route::get('/my-classes/add-new-class', ['uses'=>'ClassController#createNewClass'])->name('user.add-new-class');
Route::post('/my-classes/save-class', ['uses'=>'ClassController#saveClass'])->name('user.save-class');
Route::get('/my-classes/edit-class/{id}', ['uses'=>'ClassController#editClass'])->name('user.edit-class');
Route::post('/my-classes/update-class/{id}', ['uses'=>'ClassController#updateClass'])->name('user.update-class');
Route::get('/my-classes/delete-class/{id}', ['uses'=>'ClassController#deleteClass']);
Route::post('/get-subjects-by-category', ['uses'=>'ClassController#getSubjectsByCategory']);
Route::post('/get-classes-by-category-and-subject', ['uses'=>'ClassController#getClassesByCategoryAndSubject']);
Route::get('/my-bookings', ['uses'=>'BookingController#getAllBookings'])->name('user.my-bookings');
Route::get('/my-bookings/view-booking-details/{id}', ['uses'=>'BookingController#viewBookingDetails'])->name('user.view-booking-details');
Route::get('/my-bookings/cancel-booking/{type}/{id}', ['uses'=>'BookingController#cancelBooking']);
Route::get('/my-bookings/accept-booking/{id}', ['uses'=>'BookingController#acceptBooking']);
Route::post('/make-a-payment', ['uses'=>'BookingController#makePayment'])->name('user.make-payment');
Route::get('/my-orders', ['uses'=>'OrderController#getAllOrders'])->name('user.my-orders');
Route::get('/messages', ['uses'=>'MessageController#getMessageThreads'])->name('user.messages');
Route::get('/messages/view-messages/{thread_id}', ['uses'=>'MessageController#getAllMessagesByThreadID'])->name('user.view-messages');
Route::post('/messages/send-message', ['uses'=>'MessageController#sendMessage']);
Route::get('/reviews', ['uses'=>'BookingController#getAllReviews'])->name('user.reviews');
});
Extended Controller.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
This rule Route::get('{locale?}', 'HomeController#index'); is catching all routes because it's always true. so Laravel follows this route.
the problem is not about Route::get('/open-chat', 'ChatController#index'); if you put any route after that one, it won't work.
we usually use this to catch all request to forward somewhere like Vuejs router or show 404 message.
Route::any('{catchall}', 'CatchAllController#handle')->where('catchall', '.*');
and these are pretty same. if you put Route::get('{locale?}', 'HomeController#index'); at the end of your router file, everything should work fine.
It's normal, var_dump doest stop the script and die should be die(). Instead, use dd(123123). Everything is fine with the controller.
Since the route doesn't have the auth middleware, we can assume that the route is open to everyone. In the controller, you are checking if the use is authenticated, if not, redirect to /.

php artisan route:list ReflectionException class does not exist but its there?

Im having this problem when i use the command said in the title, its not finding my LoginController that i have in my auth folder.
It seams that it wants to load the controller using the wrong path.
Its weird because i never touched or moved anything from that controller i was creating a migration when i notice the error trying the route:list command as for my application it works normally except when i logout it doesn't redirect to my login view anymore it no redirects to public thus showing a 404.
I don't know what i did that it broke those things.
I tried changing the namespace of my controller to the one it shows on the error but its weird because when i change it the new error shows the correct path for the controller but since i changed it does not finds it again.
Also i tried the commands: config:cache, composer dump-autoload, composer update.
This is my controller:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
My web routes:
<?php
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::namespace('Admin')->prefix('admin')->middleware(['auth', 'auth.admin'])->name('admin.')->group(function(){
Route::resource('/ImagenAudioVideo', 'PlantillaController', ['except' => ['show', 'create', 'store'] ]);
Route::resource('/Imagen', 'PlantillaImagenesController', ['except' => ['show', 'create', 'store'] ]);
Route::resource('/Audio', 'PlantillaAudiosController', ['except' => ['show', 'create', 'store'] ]);
Route::resource('/Video', 'PlantillaVideosController', ['except' => ['show', 'create', 'store'] ]);
Route::resource('/ImagenAudio', 'PlantillaImagenesAudioController', ['except' => ['show', 'create', 'store'] ]);
Route::resource('/EditarUsuario', 'EditarUsuariosController', ['except' => ['show', 'create', 'store'] ]);
Auth::routes(['register' => false]);
Route::get('/', function () {
return view('home');
});
});
The exception:
ReflectionException : Class App\Http\Controllers\Admin\Auth\LoginController does not exist
at /Applications/MAMP/htdocs/ConfiguradorIEM/vendor/laravel/framework/src/Illuminate/Container/Container.php:790
notice how it shows a different path but when i change the namespace to the path shown in the exception it throws a new error with the previous path.
You have two Auth::routes(); declarations, the second one has the namespace Admin.
This is why you get this error: you have to remove the line Auth::routes(['register' => false]); inside the Admin namespaced Route because you are adding the Admin namespace to all the Auth controllers.
Remember that Auth::routes(); are for the most named routes and the second route declaration override the first one.
If anyone is still searching for a solution for such an error.
In my case, the error showed up only because I forgot to specify the namespace for my controller which was in the Billing directory.
And as soon as I added this line at the top of my controller:
namespace App\Http\Controllers\Billing;
The issue was resolved.

Can't redirect users to custom URL after succesful login in Laravel

I am trying to redirect the users to a custom URL after a succesful login but it doesn't work. It keeps redirecting users to this dashboard page "/". I already deployed the website to the server so I can't clear the route cache with artisan.
Laravel version is 5.3.29
App\Http\Controllers\Auth\LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/my-profile';
protected $redirectPath = '/my-profile';
protected function redirectTo()
{
return '/my-profile';
}
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}
App\Http\Middleware\RedirectIfAuthenticated.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check())
{
return redirect('/my-profile');
}
return $next($request);
}
}
I have read that there might be some problems with Laravel in this post. It says that there might be some problems with this file: /vendor/laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUser.php, but this error was fixed in Laravel version 5.3.29, but I can see that it is fixed and 'returnTo' method should work.
/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RedirectsUser.php
<?php
namespace Illuminate\Foundation\Auth;
use Illuminate\Support\Facades\Log;
trait RedirectsUsers
{
/**
* Get the post register / login redirect path.
*
* #return string
*/
public function redirectPath()
{
Log::info("RedirectsUsers");
if (method_exists($this, 'redirectTo')) {
return $this->redirectTo();
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/homeeeee';
}
}
And my routes file:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Auth::routes();
Route::get('/', 'HomeController#index');
Route::get('/home', 'HomeController#index');
Route::get('/confirm-your-email', 'Auth\ConfirmEmailController#confirm_email');
Route::get('/confirm-email/{register_token}', 'Auth\ConfirmEmailController#index');
Route::get('/my-profile', ['as' => 'my-profile' , 'uses' => 'MyProfileController#show', 'userAlert' => null]);
Route::post('/my-profile/edit-about', 'MyProfileController#editAbout');
Route::post('/my-profile/edit-profile-picture', 'MyProfileController#editProfilePicture');
Route::get('/search/company', 'SearchController#searchCompany');
Route::get('/my-profile/add-job', 'MyProfileController#addJobPage');
Route::get('/my-profile/add-job/{id}', 'MyProfileController#addCompanyJobPage');
Route::post('/my-profile/add-a-job', 'MyProfileController#addJob');
Route::post('/my-profile/delete-job', 'MyProfileController#deleteJob');
Route::get('/users/{id}', ['as' => 'users', 'uses' => 'UserController#show']);
Route::get('/rate/user/{id}', ['as' => 'rate', 'uses' => 'RateController#showUserRate']);
Route::post('/rate/rate-user/{id}', 'RateController#rateUser');
Route::get('/invite-user-rate/{id}', 'RateController#showInviteUserToRateYou');
Route::post('/invite-rate/user/{id}', 'RateController#inviteUserToRateYou');
Route::get('/company/{id}', ['as' => 'company', 'uses' => 'CompanyController#show']);
Route::get('/rate/company/{id}', 'RateController#showCompanyRate');
Route::post('/rate/rate-company/{id}', 'RateController#rateCompany');
Route::get('/search/{page}/results/', 'SearchController#showSearchCompanies');
Route::get('/search/{page}/people/results', 'SearchController#showSearchPeople');
Route::get('/leave-a-rating/', 'SearchController#showLeaveARating');
Route::get('/invite', ['as' => 'invite', 'uses' => 'OtherAuthentificatedController#showInvite']);
Route::post('/email-invite', 'OtherAuthentificatedController#emailInvite');
Route::get('/contact', 'OtherController#showContact');
Route::post('/send-contact-email', 'OtherController#sendContact');
Route::get('/tyfcu', 'OtherController#thankYouForContactingUs');
you can run this command on your server for clear chache
if you want
php artisan cache:clear
and for redirecting you can redirect by this method
return Redirect::route('/my-profile');
think this might be help you

Resources