-
app/Http/Requests/ImageUploadRequest.php
Open in GitHubclass ImageUploadRequest extends ApiRequest { public function rules() { return [ 'image' => ['required', 'image', 'mimes:jpeg,png,jpg,gif'], ]; } }
-
app/Http/Controllers/Api/ImageController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\ImageUploadRequest; use App\Models\Image; class ImageController extends Controller { // public function store(ImageUploadRequest $request) { $image = Image::createAndSave($request->file('image')); if ($request->header('Accept') == 'text/plain') { $image = $image->resource_url; } return response($image, 201); } // }