The humble checklist is an incredible tool for quickly and accurately completing tasks that you don't do all of the time. Time and time again, checklists have saved me from making a critical error on some pretty important - and terribly mundane - tasks.
One of my all-time favorite checklists outlines how to set up and configure a new Laravel project. While the documentation does a great job of explaining how to get the ball rolling, there are still several things we need to do before we can really start working.
Without further ado, let's hop right into this checklist and configure a brand new Laravel project.
1. Create a Laravel Project
- Run
laravel new <project-name>
from the directory where we want to store our project
2. Create a MySQL Database
- From the command line, run
mysql -uroot -p
to log in to MySQL - Then, run
create database <database-name>;
to create the database
3. Update the .env
- Out-of-the-box, Laravel provides us with an
.env
file to configure our project, which we'll need to update.APP_NAME=“<app-name>”
APP_URL=http://<dev-url>
DB_DATABASE=<database-name>
DB_USERNAME=root
DB_PASSWORD=
4. Set Up Our Testing Environment
- Think you can skip this? Think again! Just kidding, it's up to you, but I highly recommend it!
- Inside of
phpunit.xml
in the root directory of our project, we can add the following lines in the<php></php>
block at the bottom<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
5. Scaffold Authentication
- In my Laravel project, I use the default auth 99% of the time. If you don't need to, then great! Feel free to skip this step, otherwise continue onward.
- From the command line, run
php artisan make:auth
6. Migrate Database
- From the command line, run
php artisan migrate
7. Initialize Git
- From the command line, run
git init
to initialize the project as a git repository - Then, run
git add .
to add all of the project files to the staging area - Finally, run
git commit -m 'initial commit'
to commit these files
8. Add the project to GitLab/GitHub/"Your Platform of Choice"
- Create a new project on your platform
- Follow the directions they provide for adding an existing local repository to a new project
9. Install JS Packages
- From the command line, run
yarn
ornpm install
to install your project's initial JavaScript dependencies
10. Update Scss files
- I like to use
.sass
files for my custom CSS, so at this point I'll make a few changes to do that. You don't have to this if you don't want to use Sass, but you might have to do some other work to use your CSS preprocessor of choice. - Delete
_variables.scss
file - Remove all of the content inside of
app.scss
- Rename
app.scss
to use.sass
- Update the reference to
app.scss
inside ofwebpack.mix.js
11. Add Any Other Initial Project Dependencies
- Now we can really start to customize our projects. To start, I'll typically add Tailwind CSS and then get coding.
- To add Tailwind CSS, follow these steps
- From the command line, run
yarn add tailwindcss --dev
ornpm install tailwindcss --save-dev
to install the package - Then run,
./node_modules/.bin/tailwind init
to generate the config file - Add
@tailwind preflight
and@tailwind utilities
toapp.sass
in that order - Add
let tailwindcss = require('tailwindcss');
to the top ofwebpack.mix.js
- Replace the
.sass()
portion of the mix code with the following:
- From the command line, run
.sass('resources/assets/sass/app.sass', 'public/css').options({
processCssUrls: false, postCss:[ tailwindcss(‘./tailwind.js') ],
});
- From the command line, run
npm run production
to make sure everything is working correctly and to generate your CSS file
12. Start Coding
- That's it! You're ready to start coding.
The Wrap-Up
I hope this checklist can help you get a new Laravel project up and running, and show you how useful checklists can be. This isn't something that anyone does often, so having this checklist handy prevents us from making obvious mistakes that take time away from actually coding! As always, feel free to ask me any questions on Twitter. And until next time, happy coding!