Hi guys please help, I'm working on an app that will display multiple images on view.
''
for now, I can be able to upload and save the images in the public path but I can not display them on view.
Note: I WAS ABLE TO DISPLAY one on view but displaying all the images user upload at once is not working please help
Here is my controller
$title = $request->input('title');
$user_id = Auth::user()->id;
$body = $request->input('body');
$location = $request->input('location');
$category = $request->input('category');
if ($request->hasfile('files')) {
foreach ($request->file('files') as $file) {
$extension = $file->getClientOriginalExtension(); // getting image extension
$filename = time() . '.' . $extension;
$file->move(public_path() . 'storage/postImages/', $filename);
$imgData[] = $filename;
}
$post = new Post();
$post->title = $title;
$post->user_id = auth()->id(); // add this line
$post->body = $body;
$post->location = $location;
$post->category = $category;
$post->name = json_encode($imgData); //Don't use json
$post->image_path = json_encode($imgData); // Don't use json
$post->save();
return back()->with('success', ' Post created successfully! ');
}
}
The images are not displaying with proper CSS styling, they are just listed in the view. but once I remove the protected casts in my model and upload, then put back the code protected $casts = [
'image_path' => 'array',
];
it will display perfectly.
I don't know whats wrong
rather it should appear like this
I like each image has separate CSS slide styling, instead, they all appear together with just a comer separating
them
@Snapey The image array is coming to the view quite well but they are not coming with CSS styling to make it a sliding image, rather they all display together.
but when I remover the protected casts and upload, once I add back the code, the images will display with the proper style in view. i don't know what is causing this