8

I am using Laravel 3 in one project and it's been a joy. I have also looked at the source code several times to see how some things work behind the scenes.

But now in Laravel 4, I don't know where to begin or how to understand it all. Where can I learn all the behind the scenes of Laravel 4?

Case in point: I wanted to find out if the DB::insert() returns the id of inserted row. So I started searching. 1. I found the Illuminate\Support\Facades\Facade class that "encapsulates" DB. 2. The resolveFacadeInstance function is called and then I tried to print these arrays, but my computer hangs :-/. And I'm sure this would lead to many more classes that I wouldn't understand.

Is there a way I could try to learn the inner workings of Laravel 4? Maybe stack traces?

1

5 Answers 5

15

The facade class is just a filter class to allow you to call methods as if they were static. For the facade mappings go here: http://laravel.com/docs/facades#facade-class-reference

The starting point to fully understand laravel's inner-workings should begin at:

/public/index.php

You can follow the logic of the program, noticing that requires start.php, which loads an instance of the "Application" which is found here:

/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
1
  • Hmmm, it's not much but it's a start :)
    – duality_
    Jan 16, 2013 at 7:01
4

This Tuts+ video shows a couple of ways of finding out what class is actually doing the work.

E.g.:

$root = get_class(DB::getFacadeRoot());
var_dump($root);
1

You can check out the early docs for Laravel 4 here : http://four.laravel.com/ – that should give you a good starting point

1
  • 1
    That are the docs of how to use Laravel, not the docs about the inner workings.
    – duality_
    Jan 16, 2013 at 7:03
1

The actual Laravel 4 code is well documented in the files. If you want to understand the inner workings then open up the source code files and read the notes. For example I looked up the DB::insert() code in /vendor/laravel/framework/src/Illuminate/Foundation/Application.php.

/**
 * Run an insert statement against the database.
 *
 * @param  string  $query
 * @param  array   $bindings
 * @return bool
 */
public function insert($query, $bindings = array())
{
    return $this->statement($query, $bindings);
}

Ok, so this is calling the statement function so I search for function statement in the same code / class:

/**
 * Execute an SQL statement and return the boolean result.
 *
 * @param  string  $query
 * @param  array   $bindings
 * @return bool
 */
public function statement($query, $bindings = array())
{
    return $this->run($query, $bindings, function($me, $query, $bindings)
    {
        if ($me->pretending()) return true;

        $bindings = $me->prepareBindings($bindings);

        return $me->getPdo()->prepare($query)->execute($bindings);
    });
}

We can now see that this returns the boolean result based on the comments above the code.

0

If you come from Laravel 3 this article is for you. After that you should read the other tutorials of that series.

Author's note:

This article should outline some of the more important changes to Laravel between versions 3 and the upcoming version 4. Bear in mind this isn’t all of the changes. As the release of Laravel 4 gets closer I’ll keep this article up to date. If you’re having any problems with Laravel 4 please jump on to #laravel on Freenode. At this time we’d like to ask people not to post help topics on the forums.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.