Laravel SQL request too big

668 views Asked by At

My objective

Is to create a simple DB navigator for lambda users. For this, i have a side-bar which contains all DB table_name

And at the center of the page, i want the data. Here are my table names :

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

Now, there is the code : ROUTES.PHP

Route::get('navigateur_bdd', array('uses' => 'HomeController@navigateur_bdd', 'as' => 'navigateur_bdd'));
Route::get('navigateur_bdd/{table_name}', array('uses' => 'HomeController@bdd_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));
}

The first function is the main view, when the user enters in this area.

The second function is used when the user clicks on the table_name from the sidebar of the main view

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>

What is hapenning now ? Clicking on table names such as "administratif" or "erreur" is OK

But clicking on table names which are having a prefix like "routeur_" displays a blank page, with no error. I didn't set any prefix in the database.php because not all my tables have a prefix How can i figure this out ?

EDIT : Some tables with prefix are working. Not all, i don't know why...Like "switch" prefix :

"switch"
"switch_module"

are working, but not

"switch_arp"
routeur_su
routeur_gsu

are working but not

routeur_arp

After investigating, i have blank page on tables having a lot a rows (110 000 for example) (tried with dd($selected_table)); So this changes the title of my question : How can i store those 110 000 rows in a variable ?

1

There are 1 answers

0
lukasgeiter On BEST ANSWER

You can make use of Laravels pagination functionality.
It splits your data into pages and let's you generate links to get to each page...

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

And then in your view do this to generate the links

{{ $table_name->links() }}