{"flag":true,"single":true,"pageTitle":"implement laravel fortify for authentication","post":{"id":111,"user_id":"1","slug":"implement-laravel-fortify-for-authentication-5prl","title":"implement laravel fortify for authentication","body":"<p><strong>Introduction<\/strong><br>Laravel Fortify is a powerful, flexible, and customizable authentication package for Laravel applications. It provides secure user authentication and registration, as well as password reset and email verification functionalities. This tutorial will guide you through the process of integrating Laravel Fortify into your Laravel application.<\/p>\r\n<p><strong>Step 1: Install Laravel Fortify<\/strong><br>To begin, install Laravel Fortify using composer by running the following command:<\/p>\r\n<pre class=\"language-markup\"><code>composer require laravel\/fortify<\/code><\/pre>\r\n<p><strong>Step 2: Publish the Fortify Service Provider<\/strong><br>Next, publish the Fortify Service Provider using the following command:<\/p>\r\n<pre class=\"language-markup\"><code>php artisan vendor:publish --provider=\"Laravel\\Fortify\\FortifyServiceProvider\"<\/code><\/pre>\r\n<p>This will copy necessary files to your application's configuration and actions directories.<\/p>\r\n<p><strong>Step 3: Register the Fortify Service Provider<\/strong><br>Open the config\/app.php file and register the FortifyServiceProvider by adding it to the providers array:<\/p>\r\n<pre class=\"language-markup\"><code>App\\Providers\\FortifyServiceProvider::class,<\/code><\/pre>\r\n<p><strong>Step 4: Check Routes<br><\/strong>After registering the provider, you can run php artisan route:list to see the available routes for authentication, registration, and password reset functionali<\/p>\r\n<pre class=\"language-markup\"><code>php artisan route:list<\/code><\/pre>\r\n<p><strong>Step 5: Create Views<\/strong><br>Create the necessary views for login, registration, and password reset. ie registration.blade.php<\/p>\r\n<pre class=\"language-markup\"><code>&lt;form method=\"POST\" action=\"{{ route('register') }}\"&gt;\r\n    @csrf\r\n    &lt;input type=\"text\" class=\"form-control\" id=\"name\" placeholder=\"Your Name\"&gt;\r\n    &lt;input type=\"Submit\" value=\"submit\"&gt;\r\n&lt;\/form&gt;<\/code><\/pre>\r\n<p><strong>Step 6: Customize Fortify Routes in the FortifyServiceProvider<\/strong><br>Open the<strong> app\\Providers\\FortifyServiceProvider.php<\/strong> file and customize the routes by defining the login and register views inside the boot method:<\/p>\r\n<pre class=\"language-markup\"><code>public function boot(): void\r\n{\r\n    Fortify::loginView(\"login\");\r\n    Fortify::registerView(\"register\");\r\n\r\n    \/\/ ... other code\r\n}<\/code><\/pre>\r\n<p><strong>Step 8: Save Data to Database<\/strong><br>Laravel Fortify handles saving user data to the database. The controller responsible for creating new users is located in<\/p>\r\n<p><strong>app\\Actions\\Fortify\\CreateNewUser.php.<\/strong><\/p>\r\n<pre class=\"language-markup\"><code>public function create(array $input): User\r\n    {\r\n        dd($input);\r\n        Validator::make($input, [\r\n            'name' =&gt; ['required', 'string', 'max:255'],\r\n        ])-&gt;validate();\r\n\r\n        return User::create([\r\n            'name' =&gt; $input['name'],\r\n        ]);\r\n    }<\/code><\/pre>\r\n<p><strong>Conclusion:<\/strong><br>Laravel Fortify provides a robust and customizable authentication solution for your Laravel applications. By following these steps, you can easily integrate Laravel Fortify into your project and take advantage of its powerful features for user authentication and management.<\/p>","category_id":"2","is_private":"0","created_at":"2023-04-12T05:56:38.000000Z","updated_at":"2023-04-12T05:56:38.000000Z","category":{"id":2,"user_id":"1","name":"Laravel Core","slug":"laravel-nhyt","parent_id":"1","created_at":"2023-03-14T03:58:27.000000Z","updated_at":"2023-03-20T11:30:50.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"IntroductionLaravel Fortify is a powerful, flexible, and customizable authentication package for Laravel applications. It provides secure us - implement laravel fortify for authentication (Updated: April 12, 2023) - Read more about implement laravel fortify for authentication at my programming site [SITE]","categories":[]}