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');
    }

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

 

相关文章:

  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-07-08
  • 2021-09-11
  • 2022-12-23
相关资源
相似解决方案