2. Tạo response Đối tượng response (Creating response) (ok)
https://viblo.asia/p/tap-17-response-laravel-aWj534RGK6m
Thông thường thì bạn sẽ không trả về các chuỗi hoặc mảng đơn giản trong ứng dụng. Thay vào đó bạn sẽ trả về lớp khởi tạo đầy đủ Illuminate\Http\Response hoặc view.
Trả về lớp khởi tạo đầy đủ Response cho phép chúng ta tùy chỉnh mã trạng thái (status code) của HTTP response và header. Lớp Response này kế thừa từ class Symfony\Component\HttpFoundation\Response, cung cấp nhiều method cho việc xây dựng HTTP response.
Chẳng hạn:
Route::get('home', function () {
    return response('Hello World', 200)
                ->header('Content-Type', 'text/plain');
});Ta đã thiết lập status code HTTP response là 200 thông qua tham số thứ hai của method response. Ngoài ra còn đính kèm header Content-Type: text/plain bằng phương thức header kế tiếp.
Previous1. Tạo response Chuỗi và mảng (String and array) (Creating response)Next3. Tạo response  Đính kèm header vào response (Attaching header to response)(Creating response)(ok)
Last updated
Was this helpful?
