简体   繁体   English

Laravel以表格形式发送复合主键

[英]Laravel send composite primary key in a Form

Hi i have a table Classe with composite primary key my problem is when i try to delete,update or show a row of my table for exemple for Delete : 嗨,我有一个带有复合主键的表Classe ,我的问题是当我尝试删除,更新或显示表的一行作为Delete的示例时,我的问题是:

Classe View : 类视图:

{!!Form::open(array('route'=>['class.destroy',$cl->id1,$cl->id2],'method'=>'DELETE'))!!}
{!!Form::button('Delete',['class'=>'btn btn-danger','type'=>'submit'])!!}
{!!Form::close()!!}

ClasseController ClasseController

public function destroy(Classe $classe)
    {
        $classe->delete();
        return redirect()->route('class.index')->with('message','successufuly deleted');
    }

when i click on delete i return the message successufuly deleted but the row still exist in the table , i tried to pass all the $cl using 当我单击删除时,我返回消息成功删除,但表中仍然存在该行,我尝试使用传递所有$ cl

{!!Form::open(array('route'=>['class.destroy',$cl],'method'=>'DELETE'))!!}

but it show an error : 但显示错误:

RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 205 RouteCollection.php第205行中的RouteCollection-> methodNotAllowed(array('GET','HEAD','POST'))

Eloquent不支持复合主键,因此您可以将自己的路由添加到控制器的另一个方法中,该方法将获取两个参数($ cl-> id1,$ cl-> id2),然后使用这些键找到实例模型,并做删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM