can you inspect your code and send that image url here to debug properly .. and send your images stored directory path here ?
Feb 2, 2023
12
Level 1
Image not displaying
Am stuck and can't figure out why my images are not displaying.
Index function to send the services to the view
public function index(){
$services = Service::all();
foreach($services as $service) {
$service->feature_image = Storage::url($service->feature_image);
}
return view('services.index')->with([
'services' => $services,
]);
}
Store function
public function store(Request $request){
$validate = Validator::make($request->all(), [
'title' => 'required|string',
'feature_image' => 'required|file|mimes:png,jpg,jpeg',
'description' => 'required|string|min:30|max:150',
'merchant_id' => 'required|string',
]);
if( $validate->fails() ){
return response($validate->errors(), 400);
}
//image storing before
try {
$image = $request->feature_image;
$extension = $image->extension();
if (!in_array($extension, ['jpg', 'jpeg', 'png'])) {
throw new Exception('File format not supported');
}
$imageName = time().'_'.rand(1000, 9999).'.'.$extension;
$imageName = $request->file('feature_image')->storeAs(
'feature_images',
$imageName,
'local'
);
$service = new Service();
$service->name = $request->title;
$service->feature_image = $imageName;
$service->short_description = $request->description;
$service->merchant_id = $request->merchant_id;
$service->save();
} catch (Exception $e) {
return response()->with('error', $e->getMessage());
}
$services = Service::where('merchant_id', '=', $request->merchant_id )->get();
return response()->json([
'services' => $services,
], 200);
}
View thats not displaying the images
<td>
<img src="{{$service->feature_image}}" style="max-width:300px !important; max-height:100px !important; border-radius:none !important;" />
</td>
Filesystems configuration
'local' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'visibility' => 'private',
],
and
'permissions' => [
'file' => [
'public' => 0644,
'private' => 0600,
],
'dir' => [
'public' => 0755,
'private' => 0700,
],
],
Images are uploading perfectly but just won't display
Please or to participate in this conversation.