So I have a folder inside my storage called statuses which are photos uploaded, they can be private or public, so I can't upload them to the 'public folder'
I am doing a simple uppload like so:
// If they have uploaded image(s)
foreach($request->photos ?? [] as $photo){
// Store the file
$saveFile = Storage::putFile('status/' . $status->id, $photo, 'public');
$photoAttributes = [
'name' => $photo->getClientOriginalName(),
'extension' => $photo->getClientOriginalExtension(),
'path' => $saveFile,
'size' => $photo->getSize(),
'mime' => $photo->getMimeType(),
];
$create = $status
->images()
->save(new $this->photos($photoAttributes));
}
Which uploads the file to /status/{statusid}/file
Then I save the info in the database like so:
Schema::create('files', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('extension');
$table->string('path');
$table->string('size');
$table->string('mime');
$table->integer('owner_id');
$table->string('owner_type');
$table->timestamps();
$table->softDeletes();
});
Test data
INSERT INTO `social`.`files`
(`id`,
`name`,
`extension`,
`path`,
`size`,
`mime`,
`owner_id`,
`owner_type`,
`created_at`,
`updated_at`,
`deleted_at`)
VALUES
('2',
'2m2klhq1mzzz.jpg',
'jpg',
'status/2/iu4KiozJGNRdSMSju40T1UVVnop3bWZSRddXYIe8.jpeg',
'48033',
'image/jpeg',
'2',
'App\\Modules\\Timeline\\Entities\\Timeline',
'2018-01-09 14:54:31',
'2018-01-09 14:54:31',
NULL);
The file is also being saved in the folder:
Now, when I want to display it, I am using the minme type and returning the files like so:
/**
* ------------------
* File routes
* ------------------
*/
Route::resource('photos', 'PhotosController');
/**
* Display the specified resource.
*
* @param \App\Modules\Files\Entities\Photos $photo
* @return \Illuminate\Http\Response
*/
public function show(Photos $photo)
{
$this->authorize('view', $photo);
return (new Response(Storage::get($photo->path), 200))
->header('Content-Type', $photo->mime);
}
When I visit the page to see the image, I am getting a small white square like so:
Response when I dd the stuff inside the show method
How can I fix this?