In this article I will show you how to create a simple to-do application using Laravel. Let’s start by creating the project:
composer create-project --prefer-dist laravel/laravel to_do
This will create the project in the directory to_do
. You can figure this application to work with homestead
(homestead
box for vagrant
) and serve the application using a virtualization provider like virtualbox
. However, we will just use the artisan
utility to serve the application.
On your terminal
, cd
to to_do
and issue:
php artisan serve --port 8000
If you point your browser to http://localhost:8000
you will be able to see the default Laravel
homepage.
Registration and Login
This is an essential part of almost all web applications. Adding your own registration, login and logout logic is fairly straight forward when you use Laravel
. The best thing is that quite often you simply need a simple logic that handles this and Laravel
comes with this feature out of the box.
Inorder to enable this you simply need to issue:
php artisan make:auth
That’s it! Laravel
will even create necessary views for registration, login, password reset etc.
Database
Laravel
supports connecting to different types of databases and you can configure this in .env
file. By default it has the following database entries:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
If you wish to use mysql
for your application you may want to update the entries accordingly.
For our demo, let’s use sqlite
. For this change the entries to:
DB_CONNECTION=sqlite
Now we need to tell laravel where to find the sqlite
database. To configure this open config/database.php
and you will see:
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],