Level 73
You can't have two redirects.. You either return the result which is this line return response()->json($gallery); or redirect to the homepage return redirect()->route('home'); and then fetch the images from your database there.
I want to redirect to the home page after uploading multiple images.
Controller
public function store(Request $request)
{
$path = null;
if ($request->hasFile('file'))
{
$file = $request->file('file');
$name = rand(16000,17000).time();
$extension = $file->getClientOriginalExtension();
$fileName = $name . '.' . $extension;
$path = $file->storeAs($this->path, $fileName, 'public');
}
$gallery = Media::query()->create([
'image' => $path,
]);
return response()->json($gallery);
return redirect()->route('home');
}
Please or to participate in this conversation.