Skip to content

Laravel 4 tips and resourses

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

[code lang=”php”]
$ git init
$ git clone git@github.com:laravel/laravel.git
[/code]

2. Remove some folders

Above commands will create laravel folder, so we need to go in there and remove some folders

[code lang=”php”]
$ cd laravel
$ rm –r app bootstrap vendor
[/code]

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

[code lang=”php”]
$ cd ..
$ mkdir framework
$ cd framework
$ git init
$ git submodule add https://github.com/laravel/laravel.git
[/code]

4. Run Composer to install the framework

Lastly, we need to run composer install to install the framework

[code lang=”php”]
$ composer install
[/code]

5. Adjust autoloader so it can find the framework files

Open up /laravel/public/index.php and adjust the require lines like this:

[code lang=”php”]
require __DIR__.’/../../framework/laravel/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../../framework/laravel/bootstrap/start.php’;
[/code]

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.

Laravel snippets in sublime text

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):

[code lang=”javascript”]
"auto_complete_selector": "source, text",
[/code]

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:

[code lang=”php”]
artisan key:generate
[/code]

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.

Failed redirects?

I saw some people asked about the redirects are not working in Laravel. Common mistake is to try to redirect like this:

[code lang=”php”]
Redirect::route(‘whatever’);
[/code]

Well, that can not work, you have to RETURN redirect, so proper way is:

[code lang=”php”]
return Redirect::route(‘whatever’);
[/code]

Laravel 4 resources

Tutorials

Books

Well, that’s about it. Do you have some useful tips or resources for Laravel? Please, feel free to share them in comments below.

2 thoughts on “Laravel 4 tips and resourses”

  1. How does creating the /framework/ folder separate the framework code from your application? Where do you store views, controllers, database config, etc?

    1. Well, views, controllers and everything stays in the root of the application (inside app folder). Laravel framework is installed in framework directory as Git sub-module.

      This configuration is not needed for Laravel, I was just using it in one project for my needs and wanted to share it with you guys.

Comments are closed.