*/ public function rules(): array { return [ // `mimes` reads the file, not the name. 'file' => ['required', 'file', 'mimes:csv,txt,xlsx', 'max:10240'], ]; } /** * The rules every row of a sheet is held to: the create form's own, * for the columns a sheet carries — an import cannot write what the * form refuses. The template's columns are read off them too. * * @return array */ public function rowRules(): array { return Arr::only((new StoreProductRequest)->rules(), [ 'category_id', 'name', 'slug', 'sku', 'status', 'price', 'compare_at_price', 'cost_price', 'video_url', 'description', 'is_featured', 'specs', 'specs.*', ]); } /** The uploaded spreadsheet, typed — `file()` cannot be narrowed in a subclass. */ public function spreadsheet(): UploadedFile { $file = $this->file('file'); abort_unless($file instanceof UploadedFile, 422); return $file; } }