I'm making a course on Laravel Sanctum: MasteringAuth.com

Executing commands inside your application containers

Constantin Druc ยท 13 Jun, 2021

[00:00] Before executing commands inside your application container, make sure sail is up and running. (./vendor/bin/sail up -d) This will start sail in the background. Now to stop everything you can type in ./vendor/bin/sail down

[00:23] Typing vendor bin sail every time you want to run a command is kind of annoying. Let's set up an alias for it. So we'll do alias sail="bash vendor/bin/sail", and now instead of typing in ./vendor/bin/sail down or up, or whatever else, we can just do sail up -d to start it in the background.

[00:57] With laravel sail we can execute various commands directly inside the application container. For example, to install a composer package you can do sail composer require and then the name of the package, for example sail composer require laravel/breeze --dev.

[01:24] Now if I go inside my composer.json file, we can see we have laravel breeze installed. You can also do the same thing with npm packages. For example sail npm install date-fns. Now if I open my package.json file, we can see date-fns is pulled in.

[01:47] To run the application test suit type in sail test; and it even works with flags. For example sail test --filter Feature - to only run the feature tests.

[02:00] Another thing you can do is start a new thinker session. You can do that with sail tinker. ctrl+c to escape. And finally, to initiate a mysql terminal session, you can do sail mysql.