Laravel 4 is here for a few months and is definitely becoming more and more popular each day. And when you try it, you can see why.
Laravel 4 is robust, modern MVC framework with awesome community, which really speeds things up in development process.
Here are some Laravel 4 tips and resources which will help you speed things up even further.
Laravel 4 installation tips
As some of you probably know, there are several ways to install Laravel framework and they’re all in the documentation. But, there is one way which I find interesting and that is to install Laravel 4 framework as a git sub-module.
This is handy as the framework is fully separated from our application and can be updated through Git without touching our application code.
So, let’s do it step by step here quickly:
1. Clone Laravel somewhere
$ git init
$ git clone email@example.com:laravel/laravel.git
2. Remove some folders
Above commands will create laravel folder, so we need to go in there and remove some folders
$ cd laravel
$ rm –r app bootstrap vendor
If you’re on Windows, you can do that from GUI, it’s the same.
3. Create Git sub-module for framework
Now we need to move to root folder of the project, create a framework folder and create a Git sub-module
$ cd ..
$ mkdir framework
$ cd framework
$ git init
$ git submodule add https://github.com/laravel/laravel.git
4. Run Composer to install the framework
Lastly, we need to run composer install to install the framework
$ composer install
5. Adjust autoloader so it can find the framework files
Open up /laravel/public/index.php and adjust the require lines like this:
$app = require_once __DIR__.’/../../framework/laravel/bootstrap/start.php’;
Sublime Text and other IDEs
Laravel 4 in Sublime Text
There are two very convenient Sublime Text plugins available which will increase our Laravel 4 productivity to new heights. So let’s install them.
Open Sublime Text editor and then open Package manager (Ctrl+Shift+P), type in install package and enter. When new dialog opens type in Laravel and install Laravel Snippets and after it is installed, install Laravel Blade.
Laravel Snippets will simplify the way you write your Laravel code with auto completing Laravel classes, methods, facades and namespaces.
For example, if you write Route, a dialog will open with all available snippets for Route facade.
When you enter the one needed, it will add the proper snippets along with parameters.
You can even enter something like Rou-r if you want to enter a resource Route for example.
If auto complete is not working for you in Sublime Text after installing Laravel snippets plugin, add this to your user settings (Preferences — Setting – User):
&quot;auto_complete_selector&quot;: &quot;source, text&quot;,
Sublime text Blade plugin will help you by properly coloring Blade template files.
Laravel 4 in Eclipse or NetBeans
If you want to have a better auto complete functionality in other IDEs like Eclipse and NetBeans, follow this few steps below:
1. Download the following pre-made file that lists the Laravel namespaces: https://gist.github.com/barryvdh/5227822.
2. Create a folder anywhere on your computer to hold this file. For example: C:/laravel_helper/eclipse_laravel_helper.php
3. After you created an Eclipse or NetBeans Laravel project, open project properties and adjust PHP include path to include above created folder.
Now your IDE will recognize Laravel namespaces and properly auto complete everything. Handy.
For even more goodies that can be done with Laravel IDE helper generators visit https://github.com/barryvdh/laravel-ide-helper
Change your security key for production
Laravel uses a key to salt and hash things. You should really change that key for production.
It’s really easy, just enter this in console:
This will generate new crisp 32 characters long key and enter it for you in /app/config/app.php.
If you see errors in browser after this operation, just clear browser cookies and cache.
I saw some people asked about the redirects are not working in Laravel. Common mistake is to try to redirect like this:
Well, that can not work, you have to RETURN redirect, so proper way is:
Laravel 4 resources
- Jefrey Way Tuts+ series
- LaraCasts – awesome video tutorials also by Jeffrey Way
- Excellent tutorials Here on Codeforest by Boris
- How to run Laravel on Google App Engine
Well, that’s about it. Do you have some useful tips or resources for Laravel? Please, feel free to share them in comments below.