Is spatie/laravel-html good alternative for abandoned laravelcollective/html?

1k Views Asked by At

laravelcollective/html is abandoned. I'm looking for reliable replacement. Many say spatie/laravel-html is good alternative. But I faced with problem of lack of documentation.

Example from laravelcollective/html usage:

{!! Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'patch', 'id' => 'edit-user']) !!}
 @include('users.fields')
{!! Form::close() !!}

How to made form using route with spatie/laravel-html? (Of course, I can pass url for form action from controller, but it seems less elegant solution than laravelcollective had) Is there some good documentation for spatie/laravel-html and of course, is spatie/laravel-html really good alternative for abandoned laravelcollective/html? Following spatie/laravel-html alternative not accept route as action param:

 {{ html()->modelForm($user, 'PUT', 'some/url')->open() }}
  {{ html()->text('name') }}
 {{ html()->closeModelForm() }}

Thanks in advance!

2

There are 2 best solutions below

0
AudioBubble On

Use laravel's helper route(). Depending on route it can looks like following:

{{ html()->modelForm($user, 'PUT', route('users.update', [$user->id]))->open() }} 
    {{ html()->text('name') }} 
{{ html()->closeModelForm() }}
0
bcag2 On

Documentation lacks examples.
First, don't forget to https://spatie.be/docs/laravel-html/v3/installation-setup
then here are an example (you can replace span with label):

{{ html()->form('PUT')->open() }}
{{ html()->span('Nom de l’organisme de conservation : ')->class('input-group-text') }}
{{ html()->text('name')->class('autocomplete form-control divtodrop')->placeholder('Nom de l’organisme de conservation') }}
{{ html()->span('Numéro d’inventaire')->class('input-group-text') }}
{{ html()->text('inventory_number') }}
{{ html()->span('description', 'Description')->class('input-group-text') }}
{{ html()->text('description') }}
{{ html()->submit('Ajouter le lieu de conservation')->class('btn btn-success') }}
{{ html()->form()->close() }}

and see https://spatie.be/docs/laravel-html/v1/general-usage/element-methods to see all available methods