use Illuminate\Http\Request; class ImageController extends Controller { public function store(Request $request) { // Validate the incoming request data $request->validate([ 'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048', // Example validation rules ]); // Get the image file from the request $image = $request->file('image'); // Generate a unique filename for the image $filename = uniqid('image_') . '.' . $image->getClientOriginalExtension(); // Store the image in the storage directory $storedPath = $image->storeAs('public/images', $filename); // Optionally, you may want to save the image path to the database // For example, if you have a 'photos' table with a 'path' column // Photo::create(['path' => $storedPath]); // Return a response indicating success or failure return response()->json(['message' => 'Image uploaded successfully', 'path' => $storedPath]); } }