I have a form that needs to generate slug, I use laravel-admin by z-song.
link: https://github.com/z-song/laravel-admin/
In documentation, a form can simply like this:
protected function form()
{
$form = new Form(new Post);
$form->text('title');
$form->hidden('slug');
return $form;
}
buts it's both manual input. that's not what I need since slug needs to be auto-generated.
I am trying do like this:
protected function form()
{
$form = new Form(new Post);
$form->text('title', 'Title');
$form->hidden('slug')->value(str_slug($form->title));
return $form;
}
buts its result NULL for the slug one.
so how to make it happen?
Laravel admin has some callbacks on $form, that can be useful for generating slug case :
Note : You can read more about Laravel Helpers, ex. Str::slug.