Questions tagged [laravel-response]
53 questions
2
votes
3 answers
How to change response in Laravel?
I have RESTful service that is available by endpoints.
For example, I request api/main and get JSON data from server.
For response I use:
return response()->json(["categories" => $categories]);
How to control format of response passing parameter in…

Darama
- 3,130
- 7
- 25
- 34
2
votes
2 answers
Redirecting with a message not working in Laravel 5
I have a following code in my posts.create action.
// ...
return redirect(route('posts.index'))->with('flashMessage', 'test');
// ...
I expect $flashMessage variable to be available in the posts.index view, however, it is not. What am I doing…

Alex Lomia
- 6,705
- 12
- 53
- 87
1
vote
1 answer
How to properly overwrite `Illuminate\Routing\Router::toResponse` in order to send HTTP status code 204 for empty responses?
My Laravel project has a lot of controller methods which simply return nothing or void on success. I want (more precisely need) those methods to eventually return a 204 No Content response to the client. I would like to avoid adding return…

user2690527
- 1,729
- 1
- 22
- 38
1
vote
1 answer
Laravel rest api, get the full link of the images associated with the data in database stored in uploads/posts
I am working on the Laravel project project and came across a problem. I would like my function on my ApiController.php to bring me the full links of the images from the POST table, store in uploads / posts.
so i tried this method, how can i get…

CodingStudent
- 53
- 1
- 1
- 9
1
vote
1 answer
How to return errors in Laravel Custom Request to Ajax
I made custom request as following.
class CustomRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
$rule['name']='required';
$rule['email'] =…

LoveCoding
- 1,121
- 2
- 12
- 33
1
vote
2 answers
How to handle 404 as json response if route not found?
Using Laravel 5.4, I would like to send the json response, while there is no route found in api.php, how can I archive with in api.php and without Controller and Model class.
short: How to handle when the route name is incorrect?
Tried with fallback…

151291
- 3,308
- 7
- 48
- 81
1
vote
3 answers
Laravel redirect after update uses PUT request
I have Laravel app with Vue on front end, and Vue calls update method from controller using PUT request.
Request works, model gets updated, but I have issue with redirecting as it is redirecting also as a PUT instead of simple GET?
public function…

Norgul
- 4,613
- 13
- 61
- 144
1
vote
1 answer
Cannot throw objects that do not implement Throwable
I am using Laravel 5.5. There is following class
vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php
with Method Name: buildException
In, Laravel 5.4, I was able to return JSON in this method like below.
protected…

Pankaj
- 9,749
- 32
- 139
- 283
1
vote
3 answers
laravel 5.5 FormRequest class is redirecting to me i need send array errors response
I have a problem when i validate a request with a FormRequest extended class. Because is redirecting when a bad request is recived and i need a response with the validation errors.
I'm using:
PHP 7.1.1 (cli) (built: Jan 18 2017 18:51:14) ( ZTS…

Simón Farias
- 732
- 2
- 8
- 21
1
vote
1 answer
Laravel 5.5 file download Call to undefined method BinaryFileResponse::withCookie()
After upgrading to Laravel 5.5, this code:
$headers = ['Content-Type: ' . $fileData[2]];
return Response::download($fileData[0], $fileData[1] ,$headers);
generates this error:
Call to undefined method…

Peter Matisko
- 2,113
- 1
- 24
- 47
1
vote
1 answer
Token Mismatch issue in IFrame in Internet Explorer. Laravel 5.2
What's the problem ?
I am facing Token Mismatch issue when accessing the site in IFrame in Internet Explorer.
What I tried so far ?
I search for the resolution and found this link
Below is the code that I found in the above link
App::after(function…
user5694966
1
vote
0 answers
Laravel 4.2 REST Controller returns 'Class Not Loaded' along with response
I'm making a REST call to an API I have set up in Laravel 4.2. This is a GET call, and the URL of the call is /api/v1/setup
My Route setup in Laravel is:
Route::group(array('prefix' => 'api/v1', 'after' => 'allowOrigin'), function() {
…

Gary
- 453
- 4
- 15
1
vote
1 answer
How to add HTTP Status code and status text in to response with ellipsesynergie/api-response In Laravel 5?
We will need to add status code in to the response.
Like
public function withArray(array $array, array $headers = array()) {
if ($this->statusCode == '200') {
$array = array('code' => $this->statusCode , 'success' => TRUE) + $array;
} else {
$array…

Maulik Kanani
- 642
- 6
- 22
0
votes
0 answers
Laravel Resource conditional fields
In Laravel I'm generating serialized responses using resource classes. I have the following resources: JobOffer and Business. Here is JobOfferResource::toArray method
public function toArray(Request $request): array
{
return [
'id' =>…

user3125758
- 43
- 6
0
votes
1 answer
How to fix Laravel resource is not working properly in blade view?
I'm confused why casted props are inaccessible in the blade file. When I try to check it in the controller its showing properly.
Here's the JSON shown in the browser: return $users; (here status is string)
But when I tried to show it in the view,…

schutte
- 1,949
- 7
- 25
- 45