Laravel is an awesome framework that gave refreshment to the PHP development world. Currently it is the most starred PHP project on github. I started to learn this framework two months back and right now I am working on projects using Laravel.
When I was learning Laravel, it was hard to find example Laravel code that strictly follow MVC patterns on development. Due to the flexiblty of Laravel developers tends to use it the way they like. And there was no coding best practices suggested by Laravel on their website. So I am writing this post to create sample project based MVC best practices. Project will have the following features.
- User registration
- Email verification
- User login
- Forogot password
- Remember me
1 – Setting up the development environment and cloning Laravel to a new project.
Open a terminal and type the following to make composer clone Laravel project and install dependencies to our sample application. simple-app is the name of our project.
composer create-project laravel/laravel simple-app --prefer-dist
After some time your should be able to get a folder on your home folder with project files.
Now you need to change permissions of app/storage folder, since laravel stores session,caches, etc on this folder and it should be writable by others.
cd simple-app sudo chmod -R o+w app/storage
After that you have to create a apache virtual host to access the website using a local domain from the browser, currently we use simple-app.local , we need to create virtual host file in /etc/apache2/sites-available folder,
gksudo gedit /etc/apache2/sites-available/simple-app.local.conf
And paste the following code,
<VirtualHost *:80> ServerName simple-app.local DocumentRoot /home/rohith/simple-app/public <Directory /> AllowOverride All </Directory> <Directory /home/rohith/simple-app/public> AllowOverride All </Directory> </VirtualHost>
make sure you have made changes to Directory to correct location of your system.
Now we need to add the domain name simple-app.local to /etc/hosts file,
gksudo gedit /etc/hosts
add the following line,
Now we need to make sure that Apache2 rewrite module is enabled you can do this by,
sudo a2enmod rewrite
After that we enable our virtual host simple-app.local,
sudo a2ensite simple-app.local.conf
And after that we need to restart Apache2 to use our new configurations,
sudo service apache2 restart
Now it is the big time ! Open a browser and type http://simple-app.local and load the site, if everything goes right you should see the following page.
Please write your suggestions and comments.