Php Laravel框架下的自定义函数原始查询

Php Laravel框架下的自定义函数原始查询,php,mysql,performance,function,laravel-4,Php,Mysql,Performance,Function,Laravel 4,请说明我可以在Laravel framework中的何处添加自定义功能,或者安装中是否缺少某些功能? 我正在尝试使用这个函数 public function select($query, $bindings = array()) { return $this->run($query, $bindings, function($me, $query, $bindings) { if ($me->pretending()) return array();

请说明我可以在Laravel framework中的何处添加自定义功能,或者安装中是否缺少某些功能? 我正在尝试使用这个函数

public function select($query, $bindings = array())
{
    return $this->run($query, $bindings, function($me, $query, $bindings)
    {
        if ($me->pretending()) return array();

        // For select statements, we'll simply execute the query and return an array
        // of the database result set. Each element in the array will be a single
        // row from the database table, and will either be an array or objects.
        $statement = $me->getPdo()->prepare($query);

        $statement->execute($me->prepareBindings($bindings));

        return $statement->fetchAll($me->getFetchMode());
    });
}
来自教程 但我找不到修改现有Laravel框架的地方

我需要运行一个查询,从3个表中进行内部连接,收集数据并将其发布到网格中。我需要在Laravel框架中进行修改,并创建自己的函数

请帮忙。
谢谢。

是的,因此在控制器中,您有对应于路由的方法。 因此,选择与路由对应的方法,并在该方法中调用此函数

例如,在HomeController.php中

Class HomeController extends BaseController {
    public function index() {
        $yourData = DB::raw('your query');
        // if you want to inject it in your view.
        return View::make('yourtemplatename', ['yourdata' => $yourData]);
    }
}
在您的文件routes.php中

route::get('/', 'HomeController@index');
但有一种最漂亮的方式可以用雄辩的语言进行查询。
请查看文档。您的查询并不像看上去那么困难,因为它是一个连接林。

好的,那么请准确解释您想要做什么?我不明白你为什么需要创建自己的函数?你不能用查询生成器做什么?你是说用查询生成器我可以输入任何查询并调用查询来运行并从所需的数据库中获取数据吗?这是laravel文档的示例。有了这个开始,你可以做你想做的事情。$users=DB::table('users')->select(DB::raw('count(*)as user_count,status')->where('status','',1)->groupBy('status')->get();请允许我传递这样的查询SELECT*,tarifhotelprix.marque AS prixmarque FROM$tablename INNER JOIN tarifhotel ON tarifhotel.idtarifhotel=$tablename.tarifhotel\u idtarifhotel INNER JOIN typedetarif ON typedetarif.idtypedetarif=$tablename.idtypedetarif=$tablename.idTypeDecarif=$tablename.idTypeDecarif\u idTypeDecarif内部连接类型Dechambre ON typedechambre.idtypedechambre=$tablename.idtypedechambre在brockhurehotel.idbrochurehotel=$tablename.brockhurehotel_idbrochurehotel WHERE tarifhotel.idtarifhotel='$idtarifhotel'和brockhurehotel.idbrochurehotel='$idbrochurehotel'上加入brockhurehotel.idbrockhurehotel'当然可以忘记查询生成器,只需在编写时传递字符串即可:DB::raw('sql expression here');谢谢你,如果它必须在函数索引()中,因为我已经有了公共函数索引(){//get all the nerds$nerds=Nerd::all();//加载视图并传递nerds return view::make('nerds.index')->with('nerds',$nerds);}