Create a Laravel 8 Blog - Part 3: Authentication


Install the UI theme

We are going to make use of the laravel/ui utilities to get a basic style and authentication setup in place.

  1. Install the utility
./vendor/bin/sail composer require laravel/ui
  1. Load the bootstrap UI along with the authentication controllers/views
./vendor/bin/sail artisan ui bootstrap --auth

Build the JS/CSS

  1. Install the npm packages that will allow us to build the CSS/JS
./vendor/bin/sail npm install
  1. Build the compiled CSS/JS so the front-end has files to load. You may see broken styling if this is not done.
./vendor/bin/sail npm run prod

It will wipe out the app.blade.php we had set up before. That is OK.

The [layouts/app.blade.php] view already exists. Do you want to replace it? (yes/no) [no]: > yes

Clean up default files

Some welcome blade files and routes are automatically generated that we'll clean up.

  1. Remove the resources/views/welcome.blade.php file. We'll replace it with the new blade file created by using laravel/ui.
git rm resources/views/welcome.blade.php
  1. Update the / route in routes/web.php to point to the home.blade.php file.

See the commit

Create the admin account

If you load the site, http://localhost:6001, you'll now see Log in and Register in the top right of the page. Click Register and fill it out. We will turn this into your admin account.

Login and register buttons

We don't have an admin interface to work with users, so for now we'll manually adjust it from SQL.

  1. Connect to mysql
./vendor/bin/sail mysql
  1. Run the SQL to set your role to admin
UPDATE users SET role='admin' where ID='1';


That's it for now. Part 4 will go through adding controllers/views to manage blog posts now that we have an admin user.

Next: Post CRUD

If you have any feedback for me, I'd love to hear it - corrections, alternative paths, you name it! Send me an email