what are reponses in laravel framework

 

 

 

 

 

 

 

 

how to redirect user to default page when nothing you want to display or user wanna to see something or you do want user see it and he makes a request then you want that reponse should be created to user all is done by server.Take it easy!

what are reponses in laravel framework and how we can make them in laravel.

Server handles itself what you have commanded to server .
1 <?php
2
3 // app/routes.php
4
5 Route::get(‘/’, function()
6 {
7 return ‘you are allowed to do this’;
8 });

And we can get all in beautiful html response page
<?php

// app/routes.php

Route::get(‘/’, function()
{
return ‘<!doctype html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>Sorry</title>
</head>
<body>

<p>Sorry server is ready but you are not allowed to do so !</p>
</body>
</html>’;
});
very nice and tricky feature , you see what we have done it in laravel it is so easy and not so much complicated,
but when we use other framework , there complexity also begins.
thanks for reading !
——————————————–

how we can create custom response with http status code
<?php

// app/routes.php

Route::get(‘custom/response’, function()
{
return Response::make(‘Hello world!’, 501);
});

 
replace it with the following
<?php

// app/routes.php

Route::get(‘custom/response’, function()
{
$response = Response::make(‘Hello world!’, 501);
$response->headers->set(‘our key’, ‘everything is not fine’);
return $response;
});

 
<?php

var_dump($response->headers);
Using the set() method on this collection we can add our own header to the collection by providing
a key as a first parameter and the associated value as the second.
Once our header has been added we simply return the response object as we have done previously.
The browser will receive the headers along with the response and can use this information however
it wishes.

To indicate that the content is markdown and not HTML we will modify the Content-Type header.
The Content-Type is a common header key used by browsers to distinguish between the various
formats of content that are sent to them. Don’t be confused! Let’s have an example.
<?php

// app/routes.php

Route::get(‘markdown/response’, function()
{
$response = Response::make(‘***sorry , there is some error***’, 501);
$response->headers->set(‘Content-Type’, ‘text/x-markdown’);
return $response;
});