Can I suggest using controllers. Mixing a method like that isn't very good practice :)
Also, what html? The html from the /admin/testimonial page?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have made laravel project that works with both api and web, but the problem is api returns html page when i upload image to it My controller
public function store(Request $request)
{
$data = new Testimonial;
$data->name = $request->name;
$data->description = $request->description;
$data->designation = $request->designation;
$data->company = $request->company;
if ($request->hasfile('image')) {
$file = $request->file('image');
$extenstion = $file->getClientOriginalExtension();
$filename = time() . '.' . $extenstion;
$file->move('uploads/testimonial/', $filename);
$data->image = $filename;
}
$data->save();
if (!request()->expectsJson()) {
return \Redirect::to('/admin/testimonial/');
} else {
return response()->json([$data, 'message' => 'Success'], 200);
}
}
Please or to participate in this conversation.