6. Lấy request method (Retrieving the request method) (ok)

https://viblo.asia/p/tap-16-request-laravel-aWj534Y8K6m

Cái này thì khá dễ hiểu, ta chỉ cần sử dụng phương thức method để lấy method HTTP hiện tại của request. Ngoài ra, ta có thể kiểm tra method HTTP của request hiện tại bằng phương thức isMethod với tham số truyền vào là method HTTP bạn muốn khớp với method HTTP của request hiện tại.

use Illuminate\Http\Request;

Route::get('/', function (Request $request) {
    echo 'Current method HTTP: ' . $request->method() . '<br>';
    
    if ($request->isMethod('get')) {
        echo 'This is GET method HTTP';
    }
});

Một kết quả mong đợi:

Last updated