0

I'm trying to retrieve data from my database and send them to my view to visualize them in a datatable.

When I first refreshed the page, I could see the result showing my view but then I'm getting this problem:

This page does not work This request can not be processed via localhost at this time and HTTP ERROR 500

Here's my controller code :

public function  index()
{

    $Commandes =  DB::connection('sqlsrv2')->table('Commande_nadine')
        ->get();

    return view('detailsCommandes',compact('Commandes'));
}

My HTML Code :

<thead>
  <tr>
    <th>ID Commande</th>
    <th>Date Commande</th>
    <th>Numéro de commission</th>
    <th>Année</th>
    <th>Marque</th>
    <th>Modèle</th>
    <th>Finition</th>
    <th>Reférence LC</th>
  </tr>
</thead>
<tbody>
  @foreach($Commandes as $Commande)
  <tr>
    <td>{{$Commande->RECID_NADIN}}</td>
    <td>{{$Commande->DATE_DOCUMENT_CMD_ACHAT_FRS}}</td>
    <td>{{$Commande->Num_Commission_NADIN}}</td>
    <td>{{$Commande->Annee}}</td>
    <td>{{$Commande->CodeMarque}}</td>
    <td>{{$Commande->CodeModele}}</td>
    <td>{{$Commande->CodeFinition}}</td>
    <td>{{$Commande->REF_LC_BANQUE}}</td>

  </tr>
  @endforeach

</tbody>

and here's my route :

 Route::get('/detailsCommandes', 'CommandeNadineController@index')->name('details');

Can you tell me what's not working here?

Md.Sukel Ali
  • 2,987
  • 5
  • 22
  • 34
M_M
  • 491
  • 2
  • 10
  • 22
  • Check in the application logs to see if there are unhandled exceptions logged there. – Oluwafemi Sule Feb 03 '19 at 09:35
  • I'm getting this : **local.ERROR: Allowed memory size of 134217728 bytes exhausted (tried to allocate 34497832 bytes)** – M_M Feb 03 '19 at 09:41
  • 1
    I suggest that you try paginating the query. Looks like you may have a large number of records in the database and loading them altogether in memory is causing that error. – Oluwafemi Sule Feb 03 '19 at 09:44
  • Indeed, It's the reason for the problem. However, if I paginate my query it will show me just the number of the rows I've mentioned in paginate() while writing my query and in my case I need to retrieve all the records. – M_M Feb 03 '19 at 10:01
  • @M_M try this @ https://stackoverflow.com/questions/16175153/allowed-memory-size-of-262144-bytes-exhausted-tried-to-allocate-24576-bytes – Iftikhar uddin Feb 03 '19 at 10:02
  • @Iftikharuddin that solution didn't work for me :( – M_M Feb 03 '19 at 10:09

1 Answers1

1

look at using cursor() when querying and running into memory issues. https://laravel.com/docs/5.7/eloquent#chunking-results

also try select only the db columns you need instead of returning the full record i. e. SELECT * FROM table can be very expensive especially if you are not using all the data

nick
  • 126
  • 4