PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 4, 2022

[FIXED] Laravel - Middleware How to change route to our desired page other than Login

 March 04, 2022     laravel, laravel-5.3, middleware, php     No comments   

Issue

I m working on fresh laravel project.

I had install the laravel framework through composer then I created a route for testing purpose like this:

Route::get('/', function () {
return view('pages.home');
 });

This worked fine and I got the desired page. Now for understanding middleware I added this line of code:

Route::get('/', function () {
return view('pages.home');
 })->middleware('auth');

Now its throwing error of

Route [login] not defined.

What I know that, it throwing this error because I havent install any voyagers package thats why it not finding 'login' route.

But My question is How can I change that Route [login] to my desired page like Route [pages.notauth].

Please help me for this.


Solution

First run php artisan make:auth to make the Laravel auth boilerplate. Then in the LoginController add the the following:

class LoginController extends Controller {
    use AuthenticatesUsers;
    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function showLoginForm() {
           return view("pages.notlogin");
     }


 }


Answered By - apokryfos
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing