F
Filament11mo 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
developer11mo ago
you can access the model via static::getModel() @Shiv if it works mark this as solved
Shiv
ShivOP11mo ago
i want the record
Shiv
ShivOP11mo ago
No description
Shiv
ShivOP11mo ago
it just return the string
developer
developer11mo ago
No description
developer
developer11mo ago
@Shiv have you tried using the model in any way? you can query, create, delete, etc
Shiv
ShivOP11mo 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
developer11mo 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
ShivOP11mo 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.PB9mo ago
@Shiv I have the same problem. Did you manage to access the record?
Shiv
ShivOP9mo ago
it doesnt have that feature you can either use select field or show 2 seperate fields using fieldinput
Andy.PB
Andy.PB9mo 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