Laravel 4 came out

    The long-awaited release of the fourth version of the wonderful framework took place.
    The official site has also been updated .

    Quick installation


    To install Laravel, download a copy of the repository from Github .
    Next, after installing Composer , run the composer install command in the root folder. Composer downloads and installs all the dependencies.

    Mini review


    Routing

    Subdomains

    Route::group(array('domain' => '{account}.myapp.com'), function()
    {
        Route::get('user/{id}', function($account, $id)
        {
            //
        });
    });
    

    Prefixes

    for all routes starting with / admin /
    Route::group(array('prefix' => 'admin'), function()
    {
        Route::get('user', function()
        {
            //
        });
    });
    


    Assigning a Model to a Route Parameter

    Route::model('user', 'User');
    

    Now we define a route with the parameter {user}
    Route::get('profile/{user}', function(User $user)
    {
        //
    });
    

    Laravel will load the model Useron pk itself

    Controllers

    Resource Controllers

    Resource controllers make it easy to create RESTful controllers. For example, you may need to create a controller that controls the “photos” in your application. Using controller:makethrough the Artisan CLI

    To create a controller from under the console, run the following command:
    php artisan controller:make PhotoController
    

    Now we can define the resource of the route:
    Route::resource('photo', 'PhotoController');
    

    One definition of a route can handle many different RESTful actions of our photo resource.

    Actions handled by the resource controller
    A typeWayActRoute
    Get/ resourceindexresource.index
    Get/ resource / createcreateresource.create
    Post/ resourcestoreresource.store
    Get/ resource / {id}showresource.show
    Get/ resource / {id} / editeditresource.edit
    PUT / PATCH/ resource / {id}updateresource.update
    DELETE/ resource / {id}destroyresource.destroy

    Rest controllers

    Assigning a controller to a route
    Route::controller('users', 'UserController');
    

    controller The method takes two arguments. The first is the base URI that the controller processes, and the second is the name of the controller class. Next, just add the methods in the controller, with a prefix corresponding to the type of HTTP:
    class UserController extends BaseController {
        //GET /user/index
        public function getIndex()
        {
            //
        }
        //POST /user/profile
        public function postProfile()
        {
            //
        }
    }
    

    If your controller’s action contains multiple words, you can access them through a dash in the URI. For example, the current controller action UserControllerwill process the users/admin-profileURI:
    public function getAdminProfile() {}
    


    Facade

    Facades provide a “static” interface to classes that are accessible through an IoC container . Laravel uses facades everywhere, and you can use them without even knowing it.
    For example, an implementation of a classCache
    $value = Cache::get('key');
    

    However, if you look at the class Illuminate\Support\Facades\Cache, you will notice that there is no methodget
    class Cache extends Facade {
        /**
         * Get the registered name of the component.
         *
         * @return string
         */
        protected static function getFacadeAccessor() { return 'cache'; }
    }
    

    The Cache class inherits from the Facadeclass, and defines a method getFacadeAccessor()that returns the key name in the IoC container.

    Alternative implementation Cache::getwithout the use of a facade
    $value = $app->make('cache')->get('key');
    


    If interested, you can follow the links. Github Quick Start

    Documentation


    Also popular now: