3

I am learning Laravel as my first framework, I saw, they have own syntax for create forms eg:

Laravel Inputs:

    {{ Form::text('email', '', array('placeholder' => 'Email')) }}
    {{ Form::password('password', array('placeholder' => 'Password')) }}
    {{ Form::submit('Login', array('class' => 'btn btn-success')) }}

HTML Inputs:

<input type="text" name="email" placeholder="Email"/>
<input type="password" name="password" placeholder="Password"/>
<input type="submit" name="submit" value="Login" class="btn btn-success"/>

what are the advantages, I can get, if i use Laravel syntax for create forms? thank you

Alternatex
  • 1,505
  • 4
  • 24
  • 47
Gayan
  • 2,845
  • 7
  • 33
  • 60

3 Answers3

2

There are many advantages of using the Laravel syntax.

  1. The Laravel Form automatically adds CSRF protection .
  2. You can autofill form easily using the Form::model() instead of the plain PHP.
  3. Your code remains clean and consistent and is not filled with a mix of HTML and PHP
  4. It gives extensibility i.e others can dynamically insert form elements. This is useful only if you are building a software for others to use.
adi rohan
  • 796
  • 1
  • 10
  • 26
1
  • Cleaner syntax. Compare for example a traditional HTML select vs using Form::select('name', $array).
  • Integrated CSRF protection.
  • Integrated URLs to named routes, actions and RESTful controllers of your application. If use routes in your form URL and you cange a route URL all your models will still work.
  • Form Model Binding to populate form with data from your models.
  • Automatic form fields population with flash (old) input.
  • Extendable and customizable with macros. Think if all your fields need a class but that class may change on future. If you use a macro to set that class when it changes in the future you only have to update one line of code instead of all your views.
  • Possible integration with popular CSS frameworks to add their look and field + automatic error appending. example
Javi Stolz
  • 4,720
  • 1
  • 30
  • 27
0

Laravel's Blade syntax based on ASP.NET's Razor can be very useful because it allows for template inheritance and it has useful syntax sugar for control structures like if and for and it helps with CSRF by assigning a token to your forms and verifying it when they're posted. Also it allows you to bind your model to a form and have the framework itself worry about filling out all the form fields. You can also even extend it by defining your own custom control structures.

Alternatex
  • 1,505
  • 4
  • 24
  • 47