OnyxException
OnyxException
FFilament
Created by OnyxException on 4/18/2025 in #❓┊help
“Undefined array key 0” when uploading an image
What I’m trying to do and why I’m building an admin interface with Laravel 12, Filament 3.3 to manage my menu categories. Each category should optionally have a cover image:
FileUpload::make('cover_image')
->label('Cover Image')
->image()
->directory('category-covers')
->multiple(false)
->maxFiles(1)
->nullable();
FileUpload::make('cover_image')
->label('Cover Image')
->image()
->directory('category-covers')
->multiple(false)
->maxFiles(1)
->nullable();
What I did so far - Added the cover_image column via migration and included it in my Category model’s $fillable. - Ran php artisan view:clear, config:clear, etc. - Enforced single-file upload with multiple(false) and maxFiles(1). - created a single resource just for file uploads to test it Still, the upload process fails with:
ErrorException: Undefined array key 0
at vendor/livewire/livewire/src/Features/SupportFileUploads/WithFileUploads.php:40
ErrorException: Undefined array key 0
at vendor/livewire/livewire/src/Features/SupportFileUploads/WithFileUploads.php:40
Relevant parts of my setup
// composer.json (excerpt)
"require": {
"php": "^8.2",
"filament/filament": "^3.3",
"filament/spatie-laravel-translatable-plugin": "^3.3",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1",
"spatie/laravel-translatable": "^6.11"
},
// composer.json (excerpt)
"require": {
"php": "^8.2",
"filament/filament": "^3.3",
"filament/spatie-laravel-translatable-plugin": "^3.3",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1",
"spatie/laravel-translatable": "^6.11"
},
// app/Models/Category.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class Category extends Model
{
use HasTranslations;

public $translatable = ['name'];
protected $fillable = [
'parent_id',
'name',
'order',
'cover_image',
'is_food',
];
}
// app/Models/Category.php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class Category extends Model
{
use HasTranslations;

public $translatable = ['name'];
protected $fillable = [
'parent_id',
'name',
'order',
'cover_image',
'is_food',
];
}
// In CategoryResource form()
FileUpload::make('cover_image')
->label('Cover Image')
->image()
->directory('category-covers')
->multiple(false)
->maxFiles(1)
->nullable(),
// In CategoryResource form()
FileUpload::make('cover_image')
->label('Cover Image')
->image()
->directory('category-covers')
->multiple(false)
->maxFiles(1)
->nullable(),
Question: How can I configure the FileUpload so that Filament/Livewire handles cover_image without throwing “Undefined array key 0”? Any guidance or tips are greatly appreciated!
3 replies