2014-11-21 53 views
0

我的目标Laravel SQL请求太大

是创建拉姆达用户一个简单的DB导航。 对于这一点,我有一个包含所有的数据库表名

,并在中心页面,我想数据侧边栏。 这里是我的表名:

administratif 
equipement 
erreur 
etablissement 
interface_eth_routeur 
interface_eth_switch 
interface_ip_routeur 
latence 
mainteneur 
routeur_arp 
routeur_gsu 
routeur_su 
salle_visio 
site 
switch 
switch_arp 
switch_module 

现在,有代码: routes.php文件

Route::get('navigateur_bdd', array('uses' => '[email protected]_bdd', 'as' => 'navigateur_bdd')); 
Route::get('navigateur_bdd/{table_name}', array('uses' => '[email protected]_show_table', 'as' => 'bdd_show_table')); 

HOMECONTROLLER.PHP

public function navigateur_bdd() 
{ 
    $table_name = DB::select('SHOW TABLES'); 
    return View::make('navigateur_bdd', array('which_actif' => 3, 'table_name' => $table_name)); 
} 

public function bdd_show_table($argument = NULL) { 
    $selected_table = DB::table($argument)->get(); 
    $table_name = DB::select('SHOW TABLES'); 
    return View::make('navigateur_bdd', array('which_actif' => 3, 'table_name' => $table_name, 'selected_table' => $selected_table)); 
} 

第一个功能是主视图,当用户进入这个区域时。

当用户点击TABLE_NAME从主视图

NAVIGATEUR_BDD.BLADE.PHP

<div id="sidebar-wrapper"> 
    <ul class="sidebar-nav" id="sidebar"> 
     <li class="well">Liste des tables</li> 
     @for ($i = 0 ; $i < count($table_name); $i ++) 
      <li><a href="{{ URL::to('navigateur_bdd/' . $table_name[$i]->Tables_in_MYNET)}}">{{$table_name[$i]->Tables_in_MYNET}}</a></li> 
     @endfor 
    </ul> 
    </div> 

什么现在hapenning的侧边栏时,使用第二函数? 点击表名称,如“administratif”或“ERREUR”是OK

但点击其上有类似“routeur_显示空白页,没有错误的前缀表名。 我没有在database.php中设置任何前缀,因为并非我所有的表都有前缀 我怎么能解决这个问题?

编辑:一些带有前缀的表正在工作。不是所有的,我不知道为什么......就像 “开关” 的前缀:

"switch" 
"switch_module" 

正在努力,但不

"switch_arp" 
routeur_su 
routeur_gsu 

正在努力但不

routeur_arp 

经过调查,我在有很多行的表上有空白页(例如110 000)(用dd($ selected_table)尝试); 所以这改变了我的问题的标题: 我如何将这110000行存储在变量中?

+0

你能首先确保正确的控制器? – lukasgeiter 2014-11-21 13:14:18

+0

这是正确的。 每个表的名称看起来像这样是正确的: string'interface_ip_routeur'(length = 20) – 2014-11-21 13:37:11

+0

如果您使用'$ selected_table'做同样的事情? – lukasgeiter 2014-11-21 13:44:15

回答

0

您可以使用Laravels pagination功能。
它将您的数据分成页面,让我们生成链接以访问每个页面...

$selected_table = DB::table($argument)->paginate(100); // how many records you wan't on one page 

然后在你看来这样做是通过使用'DD($参数)`在表名被传递控制器的开始生成的链接

{{ $table_name->links() }}