Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

Building a Laravel form without Illuminate/html

Laravel 5 version got us confused by separating our beloved Form::open world into a separate package. Now you have to add "illuminate/html": "~5.0" to your projects, whenever you want to use forms, right? Not necessary, you can survive without it. How we would build a simple form with that package:
{!! Form::open(array('url' => 'admin/cities')) !!}
  City name:
  
{!! Form::text('title', old('title')) !!}
{!! Form::submit('Save') !!} {!! Form::close() !!}
Now, how it looks if we build it in plain Laravel/HTML:
{{ csrf_field() }} City name:

It's not that bad, is it? The only thing we need to take differently is take care of CSRF protection, which is basically done with method csrf_field(). Another example would be a DELETE form - here we need to use two additional methods.
{{ csrf_field() }} {{ method_field('DELETE') }}
As you can see, function method_field() is used for adding a hidden field like this:

Then Laravel mechanism would point that form to the correct Controller method delete(). So, the question remains open: do we really need that external illuminate/html Form functionality? Not always. Probably, depends on your skills - which would give you faster results - and on your particular usage in your application. Which one do you prefer? Do yo use that package? Tell your experience in comments.

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses