Setting up Laravel 8.x with JetStream Auth
By: Dino Cajic
Tags: PHP, Laravel, Programming, Web Development, Jetstream

If you’re not familiar yet, Laravel 8 has gone away from the auth scaffolding and is instead embracing the JetStream package. Before you can use JetStream authentication, you’ll want to make sure that you have the latest versions of PHP, composer, and the laravel installer on your system.

PHP

Make sure that you have the latest version of PHP installed. Laravel requires a PHP version greater than 7.3 as of the time that I’m writing this. Visit the official Laravel documentation to see the latest requirements.

Since there are so many ways to install PHP onto your system, I’ll leave it up to you to Google how to upgrade your PHP to the latest version. With Windows users, you’ll most likely be using WAMP or XAMPP (if you’re not using Homestead). Search for how to upgrade to the latest version of PHP for your option and then search for how to edit the environmental variable to add the latest version to the path so that it’s accessible in CMD. You can read my article on that here:

For MAC users, here are a couple of pages to get you started:

Composer

Depending on which operating system you’re using, and if you have composer installed globally or locally, the composer update process will differ. If you’re running Windows, go to https://getcomposer.org/download/ and download the latest executable file.

Run through the prompts and you’ll have the latest version installed.

For MAC users, read the documentation: https://getcomposer.org/doc/03-cli.md#self-update-selfupdate-. Run the following command if you have composer installed globally:

> sudo -H composer self-update

Verify that you have the latest version of composer. You can go to https://getcomposer.org/ and see the latest version.

Type in composer --version in your terminal to see the latest version.

composer --version

laravel installer

If you don’t have the laravel installer installed, run:

composer global require laravel/installer

You can verify that the laravel installer has been installed globally by typing the following command into your terminal:

laravel --version

There are a couple of ways to update your laravel installer. The first option is to run the update command:

composer global require "laravel/installer:^4.0"

If you check the version and it’s still not the latest version, you can uninstall and reinstall the global installer.

composer global remove laravel/installer

composer global require laravel/installer

If you don’t know what version of the laravel installer is latest one, you can always visit the laravel/installer GitHub page and check.

Verify Latest Version

Now it’s time to verify that everything works by typing in:

laravel new --help

You should see something like this:

If you see the --jet command, you’re in a good place.

Option 1: Create a new application with JetStream Authentication

Time to create a new project with the --jet flag.

laravel new test --jet

If you see this screen, you’re probably using CMD in Windows, or it just might occur anyways. It will not allow you to proceed any further and automatically Aborts.

If you’re a Windows 10 user, try Git-Bash; it should be automatically installed on your OS. Just search for Git Bash.

You’ll have the option to select which version you’d like now; I prefer livewire, so I’ll stick to that. Enter yes or no for the teams feature and hit enter.

The Laravel application with JetStream authentication will now be installed.

CD into your newly created folder.

It’s time to run the following commands:

npm install

npm run dev

I run the two commands separately since I’ve received errors when trying to run:

npm install && npm run dev

If you don’t receive any errors, you can run them both with one command. If you do, run one than the other.

Now it’s time to do some standard stuff. Open up your application in your editor. Create the database and update your .env file. It’s time to run the migrations.

php artisan migrate

Depending on your setup, you might get the following error:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: ...)

If you do, open up the AppServiceProvider from app/Providers/AppServiceProvider.php and add the following code to the boot() method:

use Illuminate\Support\Facades\Schema; public function boot()

{

Schema::defaultStringLength(191);

}

Some tables might have been added, so run:

php artisan migrate:fresh

You should see everything populate properly:

Option 2: Create a new application and then add JetStream Authentication

Create a new application by running the following command:

laravel new test2

CD into your newly created folder and open it up in your editor. Create the database and update your .env file.

Next, get JetStream with composer:

composer require laravel/jetstream

If you’re using Windows, and you’re using Git-Bash, you might notice that composer is not recognized sometimes, even though you have it installed globally. Just switch to CMD and run the command there. After completion, it’s time to install JetStream with either Livewire or Intertia options.

// LIVEWIRE

// Install JetStream with the Livewire stack without teams

php artisan jetstream:install livewire // Install JetStream with the LiveWire stack and teams

php artisan jetstream:install livewire --teams

// INERTIA

// Install JetStream with the Inertia stack without teams

php artisan jetstream:install inertia // Install Jetstream with the Inertia stack and teams

php artisan jetstream:install inertia --teams

Next, build your assets with the following commands:

npm install

npm run dev

Again, you can run the two commands as one if you don’t have any issues:

npm install && npm run dev

Finally, run the migrations:

php artisan migrate

Again, if you happen to receive an error that states that max key length is 1000 bytes, open up the AppServiceProvider from app/Providers/AppServiceProvider.php and add the following code to the boot() method:

use Illuminate\Support\Facades\Schema; public function boot()

{

Schema::defaultStringLength(191);

}

Some tables might have been added, so run:

php artisan migrate:fresh

You should see everything populate properly.

Verify the Installation

It’s time to verify that the application has everything. Run your serve command from the root folder of your project:

php artisan serve

That’s it. You have a fully functional Laravel/JetStream authentication install. You can click on Register to Register a user.

Once registered, you can log in with your user credentials.

Once you’re logged in, you’ll see your DashBoard. At the top right, if you click on your name, you’ll see a few options. Team options may not be present if you did not enable teams.

And that’s it. I think I’ve covered most of the errors that you might receive when installing Laravel with JetStream.