“Undefined array key 0” when uploading an image

Solution
It was a issue with my local php environment. After using a newer PHP version or testing it on my live server it works.
If you get this issue, try install Laravel Herd or make a clean php install.

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();


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


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"
},


// 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(),



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!
Solution
Soo, that's interesting... It works now. I believe it was a issue with my php version.
I installed 8.4 and it works, I also installed Herd and it seems like a good application... I will work with it
Was this page helpful?