Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass variables to login and register view in laravel 5.3

Tags:

laravel-5.3

I am learning and developing a project in laravel 5.3. So I stucked at a point that, to every view in this project I am passing variables to views like following.

public function index()
{
    $page_title = 'Page Title';

    return view('home', ['title' => $page_title]);
}

so in login and register controllers there are no methods to return views. And I want to pass same variables with different string values to login and registration form. so how can i do that. And secong thing I want to ask is, that how can I add a 404 error page in my project for undefined routes. and third question is that can I set 404 page to register route (www.myproject.com/register) after adding some users in my project. looking forword for reply..

like image 259
M. Ibrar Avatar asked Dec 15 '22 00:12

M. Ibrar


1 Answers

The methods to return the views are in traits, if you want to add you own logic for these methods you can simply override them by adding your own methods the class that uses the trait e.g.

RegisterController

public function showRegistrationForm()
{
    $title = 'Register';

    return view('auth.register', compact('register'));
}

LoginController

public function showLoginForm()
{
    $title = 'Login';

    return view('auth.login', compact('title'));
}

If you want to add a custom 404 error page then you just need to create that a file at resources/views/errors/404.blade.php as shown in the docs https://laravel.com/docs/5.4/errors#custom-http-error-pages

Laravel comes with a RedirectIfAuthenticated middleware that will (as the name suggests) rediect the user away from a route if they are already logged in. By default, the login and register routes already have this. If you want to change this behaviour just edit your App\Http\Middleware\RedirectIfAuthenticated class.

Hope this helps!

like image 180
Rwd Avatar answered Apr 28 '23 07:04

Rwd