请告诉我在哪里可以在Laravel框架中添加自定义功能,或者在安装中缺少什么?我试着用这个函数
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());
});
}从教程http://fideloper.com/laravel-raw-queries,但我找不到修改我现有的Laravel框架的地方。
我需要运行一个查询,从3个表中进行内部连接,并收集数据并在网格中发布。我需要修改Laravel框架并创建我自己的函数。
请帮帮忙。谢谢。
发布于 2014-03-07 15:03:50
是的,所以在你的控制器中,你有与路线相对应的方法。因此,选择与您的路由对应的方法,并在该方法中调用此函数。
例如,在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');但有一种最漂亮的方式,可以用雄辩的口才来进行询问。检查文档,因为that.Your查询并不像它看上去的那样难,因为它是一个连接的林子。
https://stackoverflow.com/questions/22252282
复制相似问题