How to change /home after login in a laravel project - laravel

I am new in laravel framework. I install the Auth Class in my project. So when I login in my project it goes to dashboard but url is ('/home'). I want to change this path and after login I want that it goes ('/dashboard'). For that jobs, which file I want to change? I have find 4 file where /home is decleared. Thats are web.php, LoginController.php, HomeController.php, RedirectIfAuthenticated.php. Which file I will change? or any more file there?
Web.php file
homeController.php file
loginController.php file
redirectIfAuthenticated.php file

There's now an easier way to do this in Laravel 6.X.
Simply change the constant in theapp/Providers/RouteServiceProvider.php file.
/**
* The path to the "home" route for your application.
*
* #var string
*/
public const HOME = '/new-url';
After that, change your route in your routes/web.php file.
Route::get('/new-url', 'Controller#method');
// If you don't want to use the HomeController, be sure to include the auth middleware.
Route::get('/new-url', 'Controller#method')->middleware('auth');
You can delete the HomeController if you're not using it in your route, won't cause any issues.

You have to add the redirectTo property to the LoginController, RegisterController, and ResetPasswordController files:
protected $redirectTo = '/';
It is well explained in the Laravel documentation:
https://laravel.com/docs/5.5/authentication#authentication-quickstart

I have come across this before... change the protected
$redirecto = /home to / in the login controller, then got to routes->web and change the Route::get('/home') to Route::get('/')->name('dashboard')
or you can just change $redirecto = "/dashboard" in the login controller and make sure that you create/update a path in the routes.
Hope it helps.

Related

add routes after login page for user

I use backpack 4 for laravel(laravel 8)and can't write a route for the user page. After login user has to get /user/dashboard or /dashboard, but the user is redirected to /admin/dashboard. How can I solve this problem?
web.php
Route::get('/', function() {
return redirect()->route('backpack.auth.login');
});
Route::get('/user/dashboard', [DashboardUserController::class, 'index'])->middleware(['web','admin']);
If your users won't ever need to use Backpack and should only able to view the dashboard, you could add a new middleware to Backpack's set of middlewares that checks if your user is an admin or a normal user to redirect them if they are not an admin.
Because Backpack registers the login routes itself, you can't just add your middleware to the route on registration. Instead you'll need to add your middleware to Backpack's admin middleware group. That's the one that gets added to all admin routes.
Steps:
Create the new middleware:
php artisan make:middleware RedirectToDashboard
Open the new middleware at app/Http/Middleware/RedirectToDashboard.php
Change the handle method to look something like this:
public function handle(Request $request, Closure $next)
{
if($request->user()->isNormalUser()) { // You need to change this to the check if the user is a normal user, that's specific to your application
return redirect()->to('dashboard'); // 'dashboard' is the name of your route, you may need to change it.
}
return $next($request);
}
Add the new middleware to Backpack's default set of middlewares in config/backpack/base.php. Open the file and look for the middleware_class entry (most likely somewhere around line 220). Add \App\Http\Middleware\RedirectToDashboard::class to the array.
Log into Backpack as a normal user and check if you get redirected.
The /admin prefix comes from the file: config/backpack/base.php.
Remove route_prefix from the file.
Your users will be redirected to /dashboard.

laravel modify how the password is checked in the authentication process

I am using laravel 5.2.
I would like to be able to change a parameter in the .env file like PASSWORD_VALIDATION=...
This could be either LARAVEL or PERSONAL.
If it is LARAVEL then it would use the standard Laravel authentication method with users and passwords in the db. But if I use PERSONAL, I would like that it uses a function I have created that will check if the email address is in the database then verify the password provided with the Active Directory in my company.
I looked at the various files and I can see I have:
app\Http\Controllers\Auth\AuthController.php
In there, I can see:
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
In this file:
vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers.php
It uses
use AuthenticatesUsers, RegistersUsers {
AuthenticatesUsers::redirectPath insteadof RegistersUsers;
AuthenticatesUsers::getGuard insteadof RegistersUsers;
So I can see in the file
vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php
My function to be changed which is:
public function postLogin(Request $request)
{
return $this->login($request);
}
I have tried to copy this one in my file app\Http\Controllers\Auth\AuthController.php but it doesn't change anything if I modify what is inside it...
Thanks
Ok, I found out why, it seems that in my routes, it is pointing to #login and not to #postLogin hence any modification applied to the function postLogin wouldn't do anything

How to route to a controller method in Laravel Moduler development?

I am using "artem-schander/l5-modular": "dev-master" for laravel moduler development.
For example i create an Admin module.
Folder structure is App/Modules/Admin.
So controller related to Admin modules placed under App/Modules/Admin/Controllers/ directory.
All routes related to Admin module are placed in App/Modules/Admin/routes.php file.
Here how it looks
Route::group(array('module' => 'Admin', 'middleware' => ['web'],'namespace' => 'App\Modules\Admin\Controllers'), function() {
Route::resource('admin', 'AdminController');
});
All view files related to admin module placed in App/Modules/Admin/Views folder.
I am trying to access Admin's index view using this route
Route::get('/', 'AdminController#index');
This route is place in laravel default routes.php file.
and when i browse ,I am getting this error
Class App\Http\Controllers\AdminController does not exist
From this i understood , laravel looking AdminController in its default path.
How can i overcome this challenge ?
You can access a controller by full qualified namespace if it is not in default path.
Try:
Route::resource('admin', '\App\Modules\Admin\Controllers\AdminController');
I have found two way to do it.
First Option
Changing the $namespace in RouteServiceProvider.php .
For me
private $namespace='\App\Modules';
So for Admin module i can use route as
Route::get('/', 'Admin\Controllers\AdminController#index');
I think this is bad idea to change Laravel's default value.
Second Option
Providing full path of the Controller.
So route would be like this
Route::get('/','\App\Modules\Admin\Controllers\AdminController#index');

Codeigniter Issue route issue

I want the following to happen
The url something.com/why-us to go to content controller
The url something.com/nepal to go to location controller
How to manage the above in CI routes
Apply the below coding in routes.php in config folder
$route['why-us'] = "content_controller";
$route['nepal'] = "location_controller";
use your desire controller

laravel 5.1 about Resetting Passwords

If I didn't log in , I can go to Route:http://localhost:8000/password/email,and show the view.
But, when I logged in,it go to Route:http://localhost:8000/home with an error
NotFoundHttpException in RouteCollection.php line 161:
I think it should also return view password.blade.php,but it did not
How to solve?
After a successful authentication the default action is to go to '/home', if there isn't the associated routes or views (controllers are provided by default) it causes the 'NotFoundHttpException' you mentioned.
If you haven't done already, you need to create the routes and views . The documentation mentions what you need to include.
If these exist already and you're wondering how to change the default behaviour of redirecting the user to '/home', you you can customize the post-authentication redirect location by defining a redirectPath property on the AuthController:
protected $redirectPath = '/dashboard';

Resources