Closed atrauzzi closed 11 years ago
GET, PUT/PATCH, and DESTROY can reference the same route. You can't infer which method you mean just based on a route.
Hmm, not necessarily when using resource routes:
<?php echo Form::open(array('route' => 'user.store')); ?>
This implies the method and could offer an opportunity for a shortcut.
Ohhh a named route. Yeah. I was thinking as in you were specifying '/user/1' or something. My bad. :)
Curious, when are you going to be able to use anything but GET
and POST
on a HTML form?
I think people are getting way too obsessive over this form class, I think a separation of concerns is nice. Markup should be left as markup and not generated by a PHP class, but that's just my opinion.
@bencorlett the Form class will automatically add the _method
hidden field when you specify a method other than GET/POST.
See:
https://github.com/laravel/framework/blob/master/src/Illuminate/Html/FormBuilder.php#L84 https://github.com/laravel/framework/blob/master/src/Illuminate/Html/FormBuilder.php#L93
:+1:
The Formation package I wrote (pre-Laravel 4 Form class) based on L3's form class does this. You can find it at http://github.com/Aquanode/Formation. You might be able to grab some stuff from the Form::resource() method and get it added to L4's native Form class. I have yet to add in all the new L4 Form class methods to Formation, but I will get around to it eventually.
I'm a relative beginner at programming and even newer to frameworks, but I was somehow expecting not to have to set the action in this situation.
I'm using a resourceful controller and bound my form to the model:
{{ Form::model($wishlist, array('action' => array('WishlistsController@update', $wishlist->id))) }}
But of course I did have to set the method:
{{ Form::model($wishlist, array(
'action' => array('WishlistsController@update', $wishlist->id),
'method' => 'put'
)) }}
So I'd also be happy to see the method handled automatically for restful/resourceful controllers if it doesn't have negative implications.
As marxtel in IRC pointed out, it would mean the same form could be used for create and edit views.
+1, in addition, why don't you make the "$wishlist->id" optional. So
{{ Form::model($wishlist, array(
'action' => array('WishlistsController@update', $wishlist->id),
'method' => 'put'
)) }}
Would be the same as
{{ Form::model($wishlist, ['action' => ['WishlistsController@update']] ) }}
I would prefer to leave any further, more advanced form stuff up to packages. It's a little distracting from the "core" framework stuff.
Right now, I have to add the
'method' => 'PUT'
parameter and others based on what I want going on. Although if it's going to accept a route, it would be pretty slick if it could infer that too!