
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 .
To install Laravel, download a copy of the repository from Github .
Next, after installing Composer , run the
for all routes starting with / admin /
Now we define a route with the parameter
Laravel will load the model
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
To create a controller from under the console, run the following command:
Now we can define the resource of the route:
One definition of a route can handle many different RESTful actions of our photo resource.
Actions handled by the resource controller
Assigning a controller to a route
If your controller’s action contains multiple words, you can access them through a dash in the URI. For example, the current controller action
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 class
However, if you look at the class
The Cache class inherits from the
Alternative implementation
If interested, you can follow the links. Github Quick Start
Documentation
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
User
on pk itselfControllers
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:make
through the Artisan CLITo 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 type | Way | Act | Route |
Get | / resource | index | resource.index |
Get | / resource / create | create | resource.create |
Post | / resource | store | resource.store |
Get | / resource / {id} | show | resource.show |
Get | / resource / {id} / edit | edit | resource.edit |
PUT / PATCH | / resource / {id} | update | resource.update |
DELETE | / resource / {id} | destroy | resource.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
UserController
will process 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, an implementation of a class
Cache
$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
Facade
class, and defines a method getFacadeAccessor()
that returns the key name in the IoC container. Alternative implementation
Cache::get
without the use of a facade$value = $app->make('cache')->get('key');
If interested, you can follow the links. Github Quick Start
Documentation