Thursday, August 13, 2015

Laravel beginner tutorial. Traits and facades

Start working with Laravel:

Laravel is offering an already configured virtual machine with everything is needed to learn it, but  for some reason you may not be able to use a virtualized environment (I am in this situation). So I will install Laravel on Windows in my EasyPHP Devserver 14.1 VC11 with PHP 6.

Installing Laravel on Windows
-following on the official documentation found here: http://laravel.com/docs/5.1/installation#basic-configuration
-composer command:

    composer create-project laravel/laravel "C:\...your preffered installation path"

After this, create a virtual host which is pointing to "public" folder under root Laravel project path.
I've heard good things about video tutorials on Laracasts but I prefer a written one.I found the site learninglaravel.com which gives you access for free at most of the content (registration needed):

1. basic routing, controllers and views:  http://learninglaravel.net/laravel5/building-our-first-website
2. authentication   -  some part of the authentication tutorial si available only for paid user so I had to figure it out myself using this tutorial:

      https://laraveltips.wordpress.com/2015/06/15/how-to-make-user-login-and-registration-laravel-5-1
and official documentation at: http://laravel.com/docs/5.1/authentication#included-authenticating

Traits:

In the Authentication process  are used traits. Is the first time when I used the concept so I did a little bit of research:
From PHP manual:   As of PHP 5.4.0, PHP implements a method of code reuse called Traits. 

Traits are a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins. 

A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance. 

Facades:

From http://laravel.com/docs/5.0/facades 
Facades provide a "static" interface to classes that are available in the application's service container. Laravel ships with many facades, and you have probably been using them without even knowing it! Laravel "facades" serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.


The Laravel facades work after an intricate logic. Probably the best article I found on this subject is found here:   http://alanstorm.com/laravel_facades

No comments:

Post a Comment