1

I am using laravel form collective for automatic form generation in project. I used same form for add and update with route model binding

{!!  Form::model($operator, ['route' => ['operator.update', $operator->id]])  !!}

and route for this is

 Route::resource('operator','OperatorController');

This generates automatic routes for method like POST for store and PUT for updates

if I use form collective then by default method is POST for both store and update if I change to PUT then it changed for both

I need automatic method detection like if I am using for store, it should be POST and PUT if it is edit form

can we do this ?

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Dhiraj Wakchaure
  • 2,596
  • 6
  • 21
  • 37

1 Answers1

1

Mainly if you want to detect both of this situation you should use Form::open for create mode and Form::model for update mode (with method PUT) like this:

@if(!empty($operator))
    {!!  Form::model($operator, ['route' => ['operator.update', $operator->id], 'method' => 'PUT'])  !!}
@else
    {!!  Form::open(['route' => ['operator.store', $operator->id]])  !!}
@endif

This above will automaticlly add _method hidden field to your form (with PUT value) on updating. You should also split for to actions (store and update) as it's in Laravel Docs about Resource Controller.

Filip Koblański
  • 9,718
  • 4
  • 31
  • 36