laravelauthenticationlaravel-6laravel-artisanlaravel-ui

How can I add Laravel Authentication to an initiated Laravel project?


is it safe to add Laravel Auth into a project that already started? I'm sure we are not using any Authentication alternative.


Solution

  • Just to provide a small overview of the project, I'm using: - Laravel 6.x - I already Import Laravel UI to use Vue.js in some components

    In case you already started your project, you just need to be aware of the following:

    1. Your project doesn't modify any of the following files:

      • app/Http/Controllers/HomeController.php
      • app/Http/Controllers/Auth/*
      • resources/js/app
      • resources/views/layouts
    2. You are not using a FrontEnd Library with Laravel UI. This is important because depending on the command you use to start the scaffolding, you can override the app.js file on /resources/js.

    3. You are not overwriting any of the routes of the Auth created by Auth::routes().

    To add the Authentication first include laravel/ui with composer:

    composer require laravel/ui
    

    Once you've installed laravel/ui you can see the new artisan's commands:

    php artisan ui --help
    

    To include the auth scaffolding, I recommend to use the following command:

    php artisan ui:auth
    

    I prefer this command because it's safer and it's confirm before overwriting any existing file.