Sunday, February 1, 2015

Một số hàm xử lý HTTP request

Tương tự các framework khác, bạn có thể lấy giá trị từng biến, set default, hoặc lấy 1 mảng các giá trị truyền lên.
Một số hàm sau rất hữu ích trong 1 số trường hợp đặc biệt

Chỉ lấy một số input nhất định: 
$input = Request::only('username', 'password');

$input = Request::except('credit_card');
Hàm làm việc với 1 mảng các inputs: sử dụng dấu chấm "."
$input = Request::input('products.0.name');
Old input: Giữ lại input cho tới request tiếp theo (giống FLASH của symfony)
Ví dụ: 
Request::flashOnly('username', 'email');

Request::flashExcept('password');
Flash & Redirect 
return redirect('form')->withInput();

return redirect('form')->withInput(Request::except('password'));
Lấy giá trị old input từ flash 
$username = Request::old('username');
Get URI & URL
$uri = Request::path();
$url = Request::url();
Kểm tra đường dẫn Matches với 1 Pattern
if (Request::is('admin/*'))
{
    //
}
Source: http://laravel.com/docs/master/requests

No comments:

Post a Comment