Exploring Code and Laravel

Posted: 2014-02-02 15:48:00

One thing I really enjoy about any of Jeffrey Way's books or videos is how he emphasizes exploring code.  

Laravel does have great docs but for me it has been best to first dig through the code. Coming from years of another PHP framework, digging though that code could still lead to not being certain about the answer just because it is was a bit different or more abstract than what I am seeing in Laravel or even Rails. 

Here was one nice example, I was trying to figure out how to pass the "PUT" method to my form using Form::model. 

Since I know these are Facades I quickly could see in config/app.php that this Form method was an alias for this path "Illuminate\Support\Facades\Form".

Then when I open that file I see it notes on the start of the file @see "\Illuminate\Html\FormBuilder" so I do that.

In there I see "public function model".

Okay that seems like a lot of work but using PHPStorm I just hold down Command and hover over the method and click on it and it takes me there!

So now I can look at the model method, see what it does and how it just calls to the open method and easily see what it needs to find my "method" setting.

        $method = array_get($options, 'method', 'post');

        // We need to extract the proper method from the attributes. If the method is
        // something other than GET or POST we'll use POST since we will spoof the
        // actual method since forms don't support the reserved methods in HTML.
        $attributes['method'] = $this->getMethod($method);

        $attributes['action'] = $this->getAction($options);

And that was it.

I also see tricks on how to do things like the "array_get" function they use (once again Command click and I see what it does)

 

 


Tags:

code