F
Filament9mo ago
Shiv

how to access current record in form function of Resource file

class OrderResource extends Resource
{
protected static ?string $model = Order::class;

protected static ?string $navigationIcon = 'heroicon-o-collection';

public static function form(Form $form): Form
{
$model = ?? //How can i access the current model here?

return $form->schema([ ]);
}
}
class OrderResource extends Resource
{
protected static ?string $model = Order::class;

protected static ?string $navigationIcon = 'heroicon-o-collection';

public static function form(Form $form): Form
{
$model = ?? //How can i access the current model here?

return $form->schema([ ]);
}
}
12 Replies
developer
developer9mo ago
you can access the model via static::getModel() @Shiv if it works mark this as solved
Shiv
Shiv9mo ago
i want the record
Shiv
Shiv9mo ago
No description
Shiv
Shiv9mo ago
it just return the string
developer
developer9mo ago
No description
developer
developer9mo ago
@Shiv have you tried using the model in any way? you can query, create, delete, etc
Shiv
Shiv9mo ago
Mmm i don't want that you have misunderstood me I want the current record not the model class For example i want the current order id not the order model class Something like
$orderId = static::getCurrentRecord()->id;
$orderId = static::getCurrentRecord()->id;
developer
developer9mo ago
ok so, why you trying to access the record in the form() method? what are you trying to do? https://filamentphp.com/docs/2.x/admin/resources/editing-records#customizing-data-before-filling-the-form check that link, you can handle form data in multiple ways but yeah it would also be more convenient if you explain what you're trying to do ❓
Shiv
Shiv9mo ago
The orders have multiple products and those products belongs to a category I want to show all products with their category name in textinput [product 1 - category 1] [Product 2 - category 2]
Andy.PB
Andy.PB8mo ago
@Shiv I have the same problem. Did you manage to access the record?
Shiv
Shiv8mo ago
it doesnt have that feature you can either use select field or show 2 seperate fields using fieldinput
Andy.PB
Andy.PB8mo ago
I found a little hack to get the record id, so i can find() the model: $form->getlivewire()->record->id
Want results from more Discord servers?
Add your server