I am inside a laravel 5.7 application, using the package barryvdh / laravel-snappy and trying everything (this code is the last attempt), to generate a dynamically PDF that has at least 2,000 pages.
This code is about my last attempt inside the view.
\DB::table(\DB::raw('`n_f_blocks`'))
->join('n_f_files', 'n_f_files.id', '=', 'n_f_blocks.n_f_file_id')
->where('n_f_files.group_id', '=', $file->id)
->where('tipo', 'saida')->orderBy('n_f_blocks.id', 'asc')->chunk(1000, function($data) {
foreach($data as $nf) :
#endphp
<tr>
<th scope="row">{{ $nf->nota }}</th>
<td>{{ $nf->chave }}</td>
<td>{{ date("d/m/Y", strtotime($nf->data)) }}</td>
<td>{{ $nf->mod }}</td>
<td>{{ $nf->ser }}</td>
<td>{{ $nf->bc_pis_original }}</td>
<td>{{ $nf->bc_cofins_original }}</td>
<td>{{ $nf->pis_original }}</td>
<td>{{ $nf->cofins_original }}</td>
<td>{{ $nf->icms_original }}</td>
<td>{{ $nf->bc_pis_processado }}</td>
<td>{{ $nf->bc_cofins_processado }}</td>
<td>{{ $nf->pis_processado }}</td>
<td>{{ $nf->cofins_processado }}</td>
<td>{{ $nf->icms_processado }}</td>
</tr>
#php
endforeach;
});
#endphp
It is possible?
I already received several errors, timeout, max memory size ..
I really do not know how to solve.
Related
I have two foreach loops:
#foreach($masseurs as $masseur)
<tr>
<td>{{ $masseur->name }}</td>
<td>{{ $masseur->visa_expire }}</td>
</tr>
#endforeach
#foreach($masseurs as $masseur)
<tr>
<td>{{ $masseur->name }}</td>
<td>{{ $masseur->passsport_expire }}</td>
</tr>
#endforeach
I would like to sort the results of the two loops with sortBy, so I assume that I need to combine them. How to do that?
In Controller:
$masseurs->sortBy('visa_expire');
In view:
#foreach($masseurs as $masseur)
<tr>
<td>{{ $masseur->name }}</td>
<td>{{ $masseur->visa_expire }}</td>
<td>{{ $masseur->passsport_expire }}</td>
</tr>
#endforeach
Property [jenis_penyedia] does not exist on this collection instance.
#php $no = 1; #endphp
#foreach($profile as $p)
<tr>
<td>{{ $no++ }}</td>
<td>{{ $p->jenis->jenis_penyedia }}</td>
<td>{{ $p->nama }}</td>
<td>{{ $p->no_ktp }}</td>
<td>{{ $p->npwp }}</td>
<td>{{ $p->bank }}</td>
<td>{{ $p->no_rek }}</td>
<td>{{ $p->email }}</td>
<td>{{ $p->no_telp }}</td>
<td>{{ $p->keahlian }}</td>
<td>{{ $p->pengalaman }}</td>
<td>{{ $p->alamat }}</td>
<td>{{ $p->pendidikan }}</td>
<td>
Eager load your jenis to Profile.
$profile = Profile::with('jenis')->get();
$p->jenis is an Eloquent Collection. This Collection may contain many Jenis model instances (because of the hasMany relationship definition). Those models have the attribute jenis_penyedia, not the Collection.
You would need to decide which model you want to get that attribute of since there potentially are many, or none. Maybe using the first one works for your needs:
{{ $p->jenis->first()->jenis_penyedia ?? "some default value" }}
I'm using Laravel 5.2, I'm trying to execute a stored procedure and display the result in a view using a foreach loop. When I run my app I get the following error message:
Trying to get property of non-object
If I use return or dump I get the following result:
Here is my controller code:
public function VentasPorSucursal() {
$values = [1, 25, 2, "NULL", "2018-08-10", "2018-08-10", "NULL", "NULL"];
$data['data'] = DB::select('SP_RPT_VENTAS2 ?, ?, ?, ?, ?, ?, ?, ?', $values);
//dump($data);
return view('reportes.index')->with('data', $data);
}
And this is my index.blade.php
<div class="table-responsive">
<table class="table table-striped table-bordered table-condensed table-hover">
<thead>
<th>Folio</th>
<th>Fecha</th>
<th>Sucursal</th>
<th>Vendedor</th>
<th>Cantidad</th>
<th>Unidad</th>
<th>DescripciĆ³n</th>
<th>Pzaz x Pq</th>
<th>Precio</th>
<th>Total</th>
<th>Total Pzaz. Vendidas</th>
</thead>
#foreach ($data as $result)
<tr>
<td>{{ $data->Folio }}</td>
<td>{{ $data->Fecha }}</td>
<td>{{ $data->Sucursal }}</td>
<td>{{ $data->Vendedor }}</td>
<td>{{ $data->Cantidad }}</td>
<td>{{ $data->Unidad }}</td>
<td>{{ $data->Descripcion }}</td>
<td>{{ $data->PzasxPq }}</td>
<td>{{ $data->Precio }}</td>
<td>{{ $data->Total }}</td>
<td>{{ $data->TotalPzasVendidas }}</td>
</tr>
#endforeach
</table>
</div>
{{$data->render()}}
Looking for an answer I found that using '->' it's for an array and maybe my code is returning the result as an object and I need to use '[]' but I don't know exactly how can I do it.
What could be the problem?
Looking at your dump result. The data array you are passing to view contains a data key which contains all of your objects returned from query. So you can loop through data variable data objects like this:
#foreach ($data['data'] as $result)
<tr>
<td>{{ $result->Folio }}</td>
<td>{{ $result->Fecha }}</td>
<td>{{ $result->Sucursal }}</td>
<td>{{ $result->Vendedor }}</td>
<td>{{ $result->Cantidad }}</td>
<td>{{ $result->Unidad }}</td>
<td>{{ $result->Descripcion }}</td>
<td>{{ $result->PzasxPq }}</td>
<td>{{ $result->Precio }}</td>
<td>{{ $result->Total }}</td>
<td>{{ $result->TotalPzasVendidas }}</td>
</tr>
#endforeach
Your first problem is in foreach loop which i reset is below and secondly
If the return result is an array it can be access like below.
#foreach ($data as $result)
<tr>
<td>{{ $result["Folio"]}}</td>
<td>{{ $result["Fecha"] }}</td>
<td>{{ $result["Sucursal"] }}</td>
<td>{{ $result["Vendedor"] }}</td>
<td>{{ $result["Cantidad"] }}</td>
<td>{{ $result["Unidad"] }}</td>
<td>{{ $result["Descripcion"] }}</td>
<td>{{ $result["PzasxPq"] }}</td>
<td>{{ $result["Precio"] }}</td>
<td>{{ $result["Total"] }}</td>
<td>{{ $result["TotalPzasVendidas"] }}</td>
</tr>
#endforeach
I want a help to change this function of a model in my project cause it returns an array like this :: [{"Package_Name":"Excel"}] i need only the string "EXCEL"
Code in model
public function getUserSeminars(){
$seminar = Seminar::select('Package_Name')
->join('Home_StudentPackages','Home_StudentPackages.hsp_PackID','=','Home_Packages.Package_ID')
->join('Home_Students','Home_Students.home_id','=','Home_StudentPackages.hsp_homeStudID')
->where('Home_Students.home_id','=',$this->home_id)
->get();
return $seminar;
}
blade
#foreach($users as $i=>$user)
<tr>
<td>{{ $i+1 }}</td>
<td>{{ $user->home_lastname }}</td>
<td>{{ $user->home_firstname }} </td>
<td>{{ $user->getUserSeminars() }}</td>
<td>{{ $user->home_id }}</td>
<td>{{ $user->getUserRights() }}</td>
#foreach($users as $i=>$user)
<tr>
<td>{{ $i+1 }}</td>
<td>{{ $user->home_lastname }}</td>
<td>{{ $user->home_firstname }} </td>
<td>
<ul>
#foreach($user->getUserSeminars() as $seminar)
<li>{{$seminar->Package_Name}}</li>
#endforeach
</ul>
</td>
<td>{{ $user->getUserSeminars() }}</td>
<td>{{ $user->home_id }}</td>
<td>{{ $user->getUserRights() }}</td>
Kind of some pseudo code, can't remember 100% correct sintaxis, but this should work.
I am using Laravel 4.2 and catching single data from DB, because foreach loop is giving me last record all time
This is foreach in my blade.php file:
#foreach($vrataMreze as $vrataMrezeVar)
<tr>
<td>{{ $vrataMrezeVar->nalogBroj }}</td>
<td>{{ $vrataMrezeVar->nazivNaloga }}</td>
<td>{{ $vrataMrezeVar->narucitelj }}</td>
<td>{{ $vrataMrezeVar->datumIzrade }}</td>
<td>{{ $vrataMrezeVar->statusProizvodnje }}</td>
<td>{{ $vrataMrezeVar->datumOtpreme }}</td>
<td>{{ $vrataMrezeVar->nacinOtpreme }}</td>
<td>{{ $vrataMrezeVar->statusPoslovnice }}</td>
<td>{{ $vrataMrezeVar->datumMontaze }}</td>
<td>{{ $vrataMrezeVar->montirano }}</td>
<td>{{ $vrataMrezeVar->isporuceno }}</td>
<td align="center"><span class="glyphicon glyphicon-ok"></span></td>
<td align="center"><span class="glyphicon glyphicon-trash"></span></td>
<td align="center"><span class="glyphicon glyphicon-edit"></span></td>
<td align="center"></span></td>
</tr>
Route for this action:
Route::get('/nalozi/mreze/vrataMrezaOpen', array('uses' => 'MrezeController#openVrataMreza', 'as' => 'openVrataMreza'));
And function from my controller:
public function openVrataMreza($id)
{
$vrataMreze = DB::table('VrataMreza')->where('id', $id)->first();
return View::make('nalozi.Mreze.Vrata_Mreze.vrataMrezaOpen')->with('vrataMreze', $vrataMreze);
}
Also I tried with
Session::set('id', $vrataMrezeVar->id);
and
Session::get('id');
but didn't work, aslo get last record from database..
Your question is not much clear , but to get last record you can modify eloquent query.
public function openVrataMreza($id)
{
$vrataMreze = DB::table('VrataMreza')->where('id', $id)->orderBy('id','DESC')->first();
return View::make('nalozi.Mreze.Vrata_Mreze.vrataMrezaOpen')->with('vrataMreze', $vrataMreze);
}