Authentification Laravel

Asked

Viewed 472 times

1

I am studying the authentication part of Laravel and basing myself on the following documentation Laravel

I followed every step:

  • I set up the database
  • I set the routes
  • I put the Views

When I walk in: (http://MEU_DOMINIO/public/auth/Register) it opens the form to register new users, but when I click on "Register"

From the following error:

Not Found The requested URL /auth/Register was not found on this server.

I see this is redirecting me to: (http://MEU_DOMINIO/auth/Register)

I tried using the helper route(...) but as this was not in the official documentation I thought it best to ask here...

Has anyone followed these steps and had the same problem? and has the solution?

  • You need to post part of your code in order to know what is occurring, in this case I believe your route file is sufficient.

  • I didn’t get to post my code here, because it’s like the Laravel documentation, but next time I put it anyway. vlw

1 answer

0


To start with scaffold for Laravel authentication, run the following command on the console:

php artisan make:auth

This will create standard views for registration and login, as well as a middleware for authentication, along with a group of routes. All you have to do is put the protected routes within that group.

Example:

Route::get('/', function () {
        return view('home.home', ['nav' => "home"]);
});


Route::group(['middleware' => ['auth']], function () {
    Route::group(['prefix' => 'products'], function () {
        Route::get('/', 'ProductController@getAll');
        Route::get('/ajax', 'ProductController@getAllAjax');
        Route::get('/stock/danger', 'ProductController@getStockDanger');
        Route::get('/ajax/{id}', 'ProductController@getOne');
        Route::post('/store', 'ProductController@store');
        Route::get('/delete/{id}', 'ProductController@deleteView');
        Route::get('/destroy/{id}', 'ProductController@destroy');
        Route::get('/edit/{id}', 'ProductController@editView');
        Route::post('/update', 'ProductController@update');
        Route::post('/search', 'ProductController@search');
        Route::get('/{id}', 'ProductController@detail');
});
Route::auth();

In this case the route that redirects to / is published while the group within the Route::group(['middleware' => ['auth']], function () {}); requires authentication. This is done from the table users created by Laravel himself.

  • Thanks, your explanation worked correctly, I only had a doubt... my file Routes.php looks like this Route::get('/', Function () { Return view('Welcome'); }); // Authentication Routes... Route:get('auth/login', 'Auth Authcontroller@getlogin'); Route::post('auth/login', 'Auth Authcontroller@postlogin'); Route::get('auth/logout', 'Auth Authcontroller@getlogout'); // Registration Routes... Route::get('auth/Register', 'Auth Authcontroller@getregister'); Route:post('auth/Register', 'Auth Authcontroller@postregister'); I don’t know how /home works for example

  • It works as follows, everything within the group where you use middleware auth will require user authentication, and what is not within it can be accessed without authenticating.

  • But for Laravel to navigate between pages I don’t need to have all routes mapped in my Routes.php file?

  • These Route::group do not have in my Routes.php file

  • open the address of your project in the php terminal type make:auth Artisan will generate what you need for authentication automatically.

  • Yes, I’ve done what you said and it’s worked okay! Even though everything works perfectly I think my Routes.php is different from how you said it should stay, so my doubt. Running this command there, as it should be Routes.php?

  • Which version of Laravel is using?

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.