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?
I know it's old but for the archive, try:
$form->hidden('slug');
$form->input('slug', $value);
Laravel admin has some callbacks on $form, that can be useful for generating slug case :
use Illuminate\Support\Str;
$form->text('title');
$form->hidden('slug');
$form->saving(function (Form $form) {
$form->slug = Str::slug($form->title);
});
Note : You can read more about Laravel Helpers, ex. Str::slug .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.