Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel return text/html and not json?

I have this in response headers:

Response headers (165 B)    
    Host    
    "localhost:8000"
    [Learn More]
    Connection  
    "close"
    [Learn More]
    Content-Type    
    "text/html; charset=UTF-8"
    [Learn More]
    Date    
    "Thu, 16 Mar 2017 14:33:53 GMT"
    [Learn More]
    Transfer-Encoding   
    "chunked"

My controller is quite simple:

public function login(Request $request){

      return response()->json([
        'name' => 'Abigail',
        'state' => 'CA'
        ]);
    }

Im using angular for post.

like image 399
uzhas Avatar asked Sep 14 '25 00:09

uzhas


1 Answers

Laravel provides modify header information using Response class.

Try this way in your controller :

$contents = View::make('embedded')->with('foo', $foo);
$response = Response::make($contents, $statusCode);
$response->header('Content-Type', 'text/plain');
return $response;
like image 51
Hiren Makwana Avatar answered Sep 15 '25 14:09

Hiren Makwana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!