Laravel-5 / Sentinel disabling default routes - php

I am using Laravel5 with Sentinel and have disabled the default routes within the sentinel.php config file:
'routes_enabled => false'
I am using the "rydurham/sentinel": "~2.2" composer package.
Now I am trying to create my own routes for the authentication system to follow. I managed to get my own custom login page displaying correctly using the following code:
Route::get('login', ['as' => 'sentinel.login', function()
{
return View::make('Auth.login');
}]);
However, i'm having a problem trying to get the route to work when the login form is posted. Here's my route:
Route::post('login', ['as' => 'sentinel.session.store', 'uses' => 'Sentinel\Controllers\SessionController#store', function()
{
}]);
I'm getting the following error:
ReflectionException in Container.php line 736: Class App\Http\Controllers\Sentinel\Controllers\SessionController does not exist

I managed to fix it by adding a \ in the route path to Sentinel Controller:
Route::post('login', ['as' => 'sentinel.session.store', 'uses' => '\Sentinel\Controllers\SessionController#store', function()
{
}]);

Related

Route Not Found Exception Route [login] not defined

In my Laravel 7.0 project, though I have login routes but still application gives an error
Symfony\Component\Routing\Exception\RouteNotFoundException
Route [login] not defined.
web.php
Route::prefix('admin')->middleware('auth')->group(function() {
Route::get('/', 'AuthController#home');
Route::get('login', 'AuthController#index');
Route::post('post-login', 'AuthController#postLogin');
Route::get('logout', 'AuthController#logout');
Route::resource('mobile-series', 'MobileSeriesController');
Route::get('mobile-series-status-update/{id}', 'MobileSeriesController#statusUpdate');
Route::resource('mobile_series_versions', 'MobileSeriesVersionController');
});
I have also applied
Route::post('login', [ 'as' => 'login', 'uses' => 'AuthController#index']);
But after using this my application gives error
This page isn’t working. localhost redirected you too many times.
How to solve this? Anybody help please?
Try getting an overview of all your routes using this command php artisan route:list.
Normally I believe your routes should look like this;
Route::get('/login', 'AuthController#index')->name('login'); OR
Route::get('/login', [AuthController::class, 'index'])->name('login');

Laravel 5.3 - Authentication is broken

About a year ago we took over an existing Laravel 5.1 site and upgraded to 5.3 - We recently became aware that an admin panel that was part of the old site no longer works (or unable to authenticate).
The original routes file contains the following:
//Login
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
//Admin
//Dashboard
Route::group(array('prefix' => 'admin', 'middleware' => 'auth'), function() {
//Dashboard
Route::get('/webadmin', array('as' => 'dashboard', 'uses' => 'Admin\DashboardController#index'));
});
Which after the upgrade stopped working as I understand the Route::controllers method was depreciated. We changed it to the following as I understand that was the replacement:
//Login
Route::resource('password','Auth\PasswordController');
Route::resource('auth','Auth\LoginController');
//Admin
//Dashboard
Route::group(array('prefix' => 'admin', 'middleware' => 'auth'), function() {
//Dashboard
Route::get('/webadmin', array('as' => 'dashboard', 'uses' => 'Admin\DashboardController#index'));
});
However, when we access the sites admin panel by example.com/admin/webadmin we are automatically redirect to example.com/login which then displays the dreadful NotFoundHttpException in compiled.php
This leads me to believe that the authentication middleware is not registered correctly. I am not sure what the correctly route is to take so will gladly appreciate any assistance :)
The redirect is happening because your not being authenticated and you are redirected to login route because the unauthenticated method in the app\Exceptions\Handler class redirects the user to /login using something like this:
return redirect()->guest('login');
So, you've to either create a /login route or change the above line to this:
return redirect()->guest('auth');
This should work and your AuthController::index method should show the login form because this will hit the index method in your AuthController because it's a resource controller.

Laravel 5.3 Login Routes - NotFoundHttpException in RouteCollection.php

I'm trying to build up my new project and i'm using Laravel 5.3.
My problem is, that the auth routes doesn't work like expected.. I allways get the following error:
NotFoundHttpException in RouteCollection.php
I removed the laravel auth routes that comes with the new update :
Those: Auth::routes();
and replaced them with:
Route::group(['middleware' => ['web']], function() {
// Login Routes...
Route::get('login', ['as' => 'login', 'uses' => 'Auth\LoginController#showLoginForm']);
Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\LoginController#login']);
Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController#logout']);
// Registration Routes...
Route::get('register', ['as' => 'register', 'uses' => 'Auth\RegisterController#showRegistrationForm']);
Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\RegisterController#register']);
// Password Reset Routes...
Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\ForgotPasswordController#showLinkRequestForm']);
Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\ForgotPasswordController#sendResetLinkEmail']);
Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\ResetPasswordController#showResetForm']);
Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\ResetPasswordController#reset']);
});
Okay now I'm trying to use them but I allways get the mentioned exception
The url I was testing: http://localhost/project/public/login
I dont know where the "public" comes from.. thats from xampp or something like that..
So this gives me the error.
if I add this route:
Route::get('/', 'Auth\LoginController#showLoginForm'); // outsite and inside of the route group
I get redirected to the Login Form and everythings fine
if I try:
Route::get('/test', 'Auth\LoginController#showLoginForm'); // same with Route::get('test', ...)
I also get the error. Does someone have a solution for that?
You can't run Laravel app like that. you need to run php artisan serve command
and then go to localhost:8000

How do I efficiently override Laravel's generated auth routes?

I have two applications, the routes file of the working one is below:
routes.php
<?php
Route::auth();
Route::group(["prefix" => "api"], function() {
Route::resource("places", "PlacesController");
Route::resource("users", "UsersController");
Route::group(["prefix" => "auth"], function() {
Route::get("/", "AuthController#GetAuth");
Route::get("logout", 'Auth\AuthController#logout');
});
});
Route::get('/', 'RedirectController#toAngular');
I have the same thing in another application but it is not working. I get an InvalidArgumentException because it can't find the login.blade.php file which I deleted because it is handled by Angular. How do I properly and most efficiently override the /login and /register GET routes generated by Route::auth()?
If you want to override /login and /register, you can just add those two routes after declaring Route::auth() like following:
Route::get('login', ['as' => 'auth.login', 'uses' => 'Auth\AuthController#showLoginForm']);
Route::get('register', ['as' => 'auth.register', 'uses' => 'Auth\AuthController#showRegistrationForm']);
As the application can't find the 'login.blade.php' which is actually returned from controller method, not in routes, then you need to override the showLoginForm method in AuthController and return what view you want to load.
public function showLoginForm() {
return view('path.to.your.view');
}

Difference between 'web' and 'auth' middleware?

I have faced some problem when i am going to use middleware group of Laravel 5.2 framework.
My routes.php file is:
Route::group(['prefix' => 'categories'], function () {
Route::get('all', ['as' => 'allCategory' , 'uses' => 'CategoryController#index']);
Route::get('add', ['as' => 'addCategory', 'uses' => 'CategoryController#create']);
Route::get('edit/{id}', ['as' => 'editCategory', 'uses' => 'CategoryController#edit']);
Route::post('save', ['as' => 'saveCategory', 'uses' => 'CategoryController#store']);
Route::put('update', ['as' => 'updateCategory', 'uses' => 'CategoryController#update']);
Route::get('delete/{id}', ['as' => 'deleteCategory', 'uses' => 'CategoryController#destroy']);
});
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController#index');
});
I am using here laravel defaults login/registration authentication.Using php artisan make:auth command.I want to give user restricted for some routes such as categories route group.So,
How can i restrict a user for categories route group?
If i use Route::group(['middleware' => ['auth']], function () { }); then i got an error. So what is the difference between 'web'
and 'auth' middleware ?
Thanks.
N.B : If you need to know about any files then just comment me below i will add those files.
This is a feature of laravel 5.2. 2 default middleware is web and api.
You need place category group route inside web middleware.
Web middleware make your request contains cookies, session, csrf_token used for authentication. Otherwise, api middleware used for application that simple query get or post without request header, assume mobile app.
Auth middleware based on web middleware.

Categories