0

Good afternoon,

I'm trying to create a link to run my destroy action. Reading the documentation of Laravel 4, it should perform as follows:

link_to_action cast ('@ getIndex HomeController', $ title, $ parameters = array (), $ attributes = array ());

My code:

{{Link_to_action ('CompaniesController @ destroy', 'Test', array ($ company-> id), array ('class' => 'btn btn btn-sm-info'))}}

But when I got to the link, it redirects me to show the controller action, when the action should send me to destroy.

Thanks in advance,

Laurence
  • 58,936
  • 21
  • 171
  • 212
cfgv
  • 69
  • 1
  • 8

2 Answers2

0

In laravel -4 use this. You are following laravel 3 format:

{{ HTML::linkAction('CompaniesController@destroy', 'Test' , array ('class' => 'btn btn btn-sm-info')) }}
Anil Sharma
  • 2,952
  • 5
  • 29
  • 45
  • following his indication the code is as follows: {{HTML :: linkAction ('CompaniesController @ destroy', 'Test', array ($ company-> id), array ('class' => 'btn btn btn-sm-info'))}} but equally it is redirecting the show method .... my destroy method is as follows: public function destroy ($ id) { $ this-> company-> find ($ id) -> delete (); return Redirect :: route ('companies.index'); } have to do something in the routes file? so is my file: Route :: resource ('companies', 'CompaniesController'); Thank you. – cfgv Feb 20 '14 at 17:02
  • what exactly you want to do ? – Anil Sharma Feb 21 '14 at 06:45
  • go to the destroy method, but without using a Form :: submit, is that I work with Ruby on Rails and in this language can create a link to delete my records, so I want to do something similar – cfgv Feb 21 '14 at 13:24
0

that method is generate a html element, and it have not DELETE method, you need a form with DELETE method to do that

Tấn Tâm
  • 130
  • 4
  • laravel four generator: scaffold, believe in it the following form to delete the record: {{Form :: open (array ('method' => 'DELETE', 'route' => array ('companies.destroy', $ company-> id)))}} {{Form :: submit ('Delete', array ('class' => 'btn btn-danger'))}} {{Form :: close ()}} Turns out to optimize the code would do with linkAction but what I see does not work, always brings me to the show method when the link clearly indicated that you go to the destroy method ... :/ – cfgv Feb 20 '14 at 16:59