How to get return from model to $form
App/Models/Jogo
class Jogo extends Model
{
use HasFactory, SoftDeletes;
protected $dates = ['deleted_at'];
public function generateslug() {
$slug = Str::random(6);
if (self::where('slug', $slug)->count() > 0) self::generateslug();
return $slug;
}
}
I want get this slug to put on my form
JogoResource
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Hidden::make('slug')
->disabled()
->default($slug_from_model_here),
3 Replies
use
mutateFormDataBeforeCreate
to create the slug
https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-savingI use for id, but how to implement for my case?
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['user_id'] = auth()->id();
return $data;
}
?