T
T
tol642020-01-16 18:24:56
Laravel
tol64, 2020-01-16 18:24:56

How to change the path to authorization in laravel and at the same time pass a parameter?

Good afternoon.
I just started learning the Laravel framework and ran into a problem, the answer to which I have not found anywhere yet. Couldn't decide on my own. Please help me figure it out.
Version
Laravel Framework 6.10.1
Task
Change the path to the authorization pages and add a parameter to the address.
Description
After executing commands

  • composer require laravel/ui
  • php artisan ui vue
  • php artisan ui:auth

... we get templates that are located in resources/views/auth and resources/views/layouts .
Now, to get to the login page in the address bar, enter the address
localhost: 8000/login
This is the default address. How to change it in such a way as to ensure the multilingualism of the site?
The address should look like this:
localhost:8000/ ru /login
localhost:8000/ en /login
... etc.
In the routes\web.php file, after executing the commands above, it is initially written:
Auth::routes();
To redefine routes, I found an option on the Internet, as in the listing below. If you now change the address for logging in, you will be able to go to the page.
// Login
Route::group(['middleware' => ['web']], function() {
    Route::get('/en/login', ['as' => 'login', 'uses' => 'Auth\[email protected]']);
    Route::post('/en/login', ['as' => 'login.post', 'uses' => 'Auth\[email protected]']);
    Route::post('/en/logout', ['as' => 'logout', 'uses' => 'Auth\[email protected]']);
});
// Registration Routes...
    Route::get('register', ['as' => 'register', 'uses' => 'Auth\[email protected]']);
    Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\[email protected]']);

// Password Reset Routes...
    Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\[email protected]']);
    Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\[email protected]']);
    Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\[email protected]']);
    Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\[email protected]']);

But, since you need to pass different values, the first part of the address should be passed as a parameter:
'/{lang}/login'
But with this option, I get an error:
[15:19:24] LOG.error: Missing required parameters for [Route: login] [URI: {url_lang}/login]. (View: C:\xampp\htdocs\laravel\poligon.local\resources\views\layouts\app.blade.php) {"exception":{}}

What changes need to be made to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tol64, 2020-01-18
@tol64

For the described task, I was completely satisfied with the solution shown in this video: https://youtu.be/_BsHyHc9NqE
In addition, some more changes need to be made. You can see more in this thread:
How to get rid of the Missing required paramete...

Y
Yuri Kulaxyz, 2020-01-16
@Kulaxyz

Go to app.blade.php and find the line there with a link to the login page, it's most likely just written somewhere. You need to add the necessary parameter there.{{route('login')}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question