Pre-requisite:
- Install your preferred version of Laravel using the Laravel Documentation.
- Insert first User in database using Database Seeder
- Create a view file for Login
- Create another file where the login will be landing
- Create a file to retrieve the error
- Modify Login Controller
- Controller for login landing page
- Add routes to web.php
We will use database seeder to create out first user. If you don't have idea about database seeder, please consider to visit Database Seeder
- Creating seeder with artisan: php artisan make:seeder UsersTableSeeder
- Open UsersTableSeeder and add the following inside run method :
- DB::table('users')->insert([
- 'name' => 'admin',
- 'email' => 'admin@email.com',
- 'password' => bcrypt('admin'),
- ]);
- Add the following inside run method of app/database/seeds/DatabaseSeeder.php
- $this->call(UsersTableSeeder::class);
- Run the artisan command: php artisan db:seed
- Create resources/views/auth/login.blade.php
- Create a layout file resources/views/layout/layout.blade.php
- Create resources/views/admin/index.blade.php
- Paste the code of LoginController to your app/HTTP/Controllers/Auth/LoginController.php
- There is already a default controller named "HomeController". We will use that.
- Paste the code of web.php
- Need to go to Illuminate\Foundation\Exceptions\Handler.php file and modify the unauthenticated method
- protected function unauthenticated($request, AuthenticationException $exception)
- {
- return $request->expectsJson() ? response()->json(['message' => $exception->getMessage()], 401) : redirect('/');
- }