F
Filament8mo ago
Mahdi

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();
$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);
}
protected $casts = [
'attachments' => 'array'
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
User Model
public function profile(): HasOne
{
return $this->HasOne(Profile::class);
}
public function profile(): HasOne
{
return $this->HasOne(Profile::class);
}
User resource
->schema([
FileUpload::make('attachments'))
->multiple(),
]),
->schema([
FileUpload::make('attachments'))
->multiple(),
]),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server