CRUD Laravel 4 how to link to destroy?

前端 未结 9 1416
你的背包
你的背包 2020-12-08 07:46

I will destroy my user with a HTML link, but it doesn\'t seem to generate the correct link, what am i doing wrong?

public function destroy($id)
{
    //Slet          


        
9条回答
  •  清歌不尽
    2020-12-08 08:21

    Another "clean" solution is to make it the Rails way as described here:

    1. Create a new .js file in public and write this function:

      $(function(){
         $('[data-method]').append(function(){
              return "\n"+
              "
      \n"+ " \n"+ "
      \n" }) .removeAttr('href') .attr('style','cursor:pointer;') .attr('onclick','$(this).find("form").submit();'); });
    2. Don't forget to include the .js file in your template after including jQuery.

    3. Use classic link_to() or link_to_method() functions to create links to delete records. Just remember to include the "data-method"="DELETE" parameter:

      {{ link_to_route('tasks.destroy', 'D', $task->id, ['data-method'=>'delete']) }}
      

    What I like about this that it seems much cleaner than bloating your code with Form::open(); in blade templates.

提交回复
热议问题