Questions tagged [laravel-response]
53 questions
18
votes
2 answers
How to set custom response for selected Request class in Laravel 5.5
I'm trying to use Laravel validation to generate custom error message, however I'm unable to find the function I should be overriding.
Route: POST:/entries/ uses EntryController@store which uses EntryStoreRequest to perform…

eithed
- 3,933
- 6
- 40
- 60
17
votes
3 answers
How i can return a customized response in a FormRequest class in Laravel 5.5?
I am making an API and i want return the array of errors with a format as the one that $validator->errors(); generates when i validate the request by the manual way. But i cant manipulate the response. I wanna find thhe correct way to make it.
This…

Simón Farias
- 732
- 2
- 8
- 21
10
votes
3 answers
Laravel - How to convert API Resource to array recursively?
I'm using Laravel API Resource and want to convert all parts of my instance to an array.
In my PreorderResource.php:
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function…

Alexandre Thebaldi
- 4,546
- 6
- 41
- 55
6
votes
3 answers
get the request values in Laravel
I wish to make search query by datepicker and select field.
How could I get the requests values from below view file to controller?
Where could I modify in the code? thanks.
index.blade.php
{!!…

JsWizard
- 1,663
- 3
- 21
- 48
5
votes
1 answer
force download file with laravel
So i'm using Laravel 5 and I tried to force download a selected file but nothing happens.
public function downloadUserFile(){
$result = $_POST['filename'];
$entry = File::where('filename', $result)->firstOrFail();
$file =…

Alex
- 485
- 6
- 18
4
votes
1 answer
Axios response data is always set as empty string in laravel
I am having some strange problem with axios I never had before, any returned response from laravel backend to vue frontend is empty..
return response()->json(['message' => 'Success!']);
This line is just after the post is edited...
I also…

Learner
- 723
- 3
- 13
- 36
4
votes
2 answers
How to send Authorization access_token to request header in Laravel using Middleware
I'm Bulid an API Authentication System. Everything I can check using Postman But I want to attach this mark portion (please see the image) that's means the header portion send from my controller or middleware with request header.
How Can I do this…

Gabrielle-M
- 1,037
- 4
- 17
- 39
3
votes
1 answer
Laravel - download PhpSpreadsheet without saving it before
I have found this approach for downloading the csv.
\Response::macro('attachment', function ($content) {
$headers = [
'Content-type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="download.csv"',
];
…

senty
- 12,385
- 28
- 130
- 260
3
votes
2 answers
Laravel 5.5 Testing JSON header doesn't work
I have a problem in testing Laravel 5.5. I need to send a Bearer Token in TEST HEADER, but doesn't work
public function testAuthCheckinvalidToken()
{
$response = $this->withHeaders([
'Accept' => 'application/json',
…

Fernando Herique Rubim Pioli
- 639
- 3
- 12
- 20
3
votes
1 answer
Manipulating Laravel html response just before sending it to browser
What is the proper way to manipulate final output before sending it to browser? (laravel 5.*)
I have created facade
namespace App\Facades;
use Illuminate\Support\Facades\Response as ResponseFacade;
use Illuminate\Http\Response as…

Adam Zygadlewicz
- 31
- 1
- 3
2
votes
0 answers
How to set isBase64Encoded: True in laravel response
I'm building an application on Laravel 8 and hosting the app on AWS lambda. I want to compress the response with gzip to HTTP request. I had interaction with AWS support and they asked me to add headers with 'Content-Encoding' => 'gzip', and also…

Rubal Gulati
- 119
- 1
- 5
2
votes
1 answer
How to return files from S3 bucket as image in Laravel?
I started use an S3 bucket in my Laravel 8.x project, and I solved file uploads to the bucket with this code:
Storage::disk('s3')->put($file_path_on_s3_drive, $file_content_as_binary);
Now I try to serve this image to the browser like this:
public…

netdjw
- 5,419
- 21
- 88
- 162
2
votes
3 answers
laravel response stream download returns empty file
I have a controller method that receives user's request for download, calls REST API endpoint with the requested body parameters.
API, in return, sends a file.
I am using Guzzle for making API requests and laravel version 5.4.
The content of the…

Azima
- 3,835
- 15
- 49
- 95
2
votes
1 answer
Laravel 6 Custom validation error 'class does not exist' when overriding FormRequest's failedValidation method
I created a custom validation class located in app\Http\Requests:

MrCujo
- 1,218
- 3
- 31
- 56
2
votes
0 answers
returning response with json in laravel api removes the collection pagination links
i'm using laravel for webservice. i want to return a collection like this:
return response()->json([data => $data]);
and i'm using laravel api resouces for transforming the collection. this is my resource:
class Item extends JsonResource
public…

E.B
- 517
- 1
- 9
- 17