FileUpload with relations

For example If User has a Profile
How to use FileUpload with Relations for saving multiple files for every user using ->multiple()



profile table
     $table->id();
     $table->foreignId('user_id')->constrained()->onDelete('cascade');
     $table->json('attachments')->nullable(); // for FileUpload multiable 
      // Other Columns 
     $table->timestamps();


Profile Model
    protected $casts = [
        'attachments' => 'array'    
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }


User Model
   public function profile(): HasOne
    {
        return $this->HasOne(Profile::class);
    }


User resource
->schema([
     FileUpload::make('attachments'))
        ->multiple(),
    ]),
Was this page helpful?