laravel中当使用Elquent ORM中的模型作为参数进行传递时的方法:

Controller中的函数:

/*

$modelArg:是调用模型的路径,以字符串的形式传递过来。

$id:要查询当前模型的id号。

$args:具体查询的字段

*/

 public function tests($modelArg,$id,$args){
        $funs=$modelArg::find($id);
        return $funs[$args];
    }

 

具体使用此函数的控制器的调用方法:

public function demos(){
        return $this->tests('App\Student',1002,'name');
    }

亲测可行,有问题,可留言。

 

posted @ 2018-03-04 11:25  生如逆旅,一苇以航  阅读(1835)  评论(0编辑  收藏  举报