📜 ⬆️ ⬇️

Laravel 4 released

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

Quick install


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 will download and install 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 the route parameter

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

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

Laravel will load the User model by pk
')
Controllers

Resource Controllers

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

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

Now we can define a resource resource:
 Route::resource('photo', 'PhotoController'); 

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

Actions processed by the resource controller
Type ofWayActRoute
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

Assign controller to the route
 Route::controller('users', 'UserController'); 

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

If your controller’s action contains several words, you can refer to them via a dash in the URI. For example, the current UserController controller action will be processed by the users/admin-profile URI:
 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, the implementation of the class Cache
 $value = Cache::get('key'); 

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

The Cache class is inherited from the Facade class, and defines a getFacadeAccessor() method that returns the name of the key in the IoC container.

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


If you are interested, you can follow the links.

Documentation
Fast start
Github

Source: https://habr.com/ru/post/181328/


All Articles