During the process of learning a new framework, there is usually a ritual you perform with each new framework installation. A half dozen laravel projects exist on my machine that I use to test ideas and try out new features. With each new install I find myself having to take the time to set up the same thing in each application.
This guide was created so I can have quick reference to these steps to save time searching the documentation.
Almost all of this information is found within the Laravel documentation.
I prefer to use composer’s
create-project command when installing Laravel. You can install the Laravel installer globally if you prefer. Either way works just fine.
$ composer create-project --prefer-dist laravel/laravel <application name>
Configuring up SQLite
This requires two parts; Setting up the local
.env database variable and creating a
While developing locally, I use php’s built in server via
php artisan serve and SQLite for my database. This let’s me get around having to set up a web server and database.
To specify SQLite as the database, open the
.env file and set
sqlite. Commenting out the other database fields is also recommended.
DB_CONNECTION=sqlite # DB_HOST=127.0.0.1 # DB_PORT=3306 # DB_DATABASE=homestead # DB_USERNAME=homestead # DB_PASSWORD=secret
By default, the
sqlite configuration is looking for the non-existant
database/database.sqlite file to use with the SQLite driver.
database.sqlite file within the
database directory. Now SQLite has a place to store the data.
$ touch database/database.sqlite
Using SQLite for unit tests
Laravel makes testing incredibly easy out of the box, but I like to tweak the
phpunit.xml file to use in-memory SQLite during my tests. It provides some speed and doesn’t require another database to be setup for testing. In fact, I actually recently wrote about this popular trick.
DB_DATABASE environment variable set to
:memory: to force the
testing instance to use memory when running tests.
<php> <env name="APP_ENV" value="testing"/> <env name="CACHE_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/> <env name="QUEUE_DRIVER" value="sync"/> <env name="DB_DATABASE" value=":memory:"/> </php>
Set up authentication
Laravel comes with a basic authentication system out-of-the-box. It’s simple and easy to use. Setting it up requires just one command.
$ php artisan make:auth
The final step
One final command before starting. Run a quick database migration and you are ready to go.
$ php artisan migrate
Open to new ideas
Have any tips? I am completely open to new ideas and workflows for setting up new Laravel applications.