Property [jenis_penyedia] does not exist on this collection instance - php

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" }}

Related

Laravel sort two foreach loop

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

Laravel - Get data from another table (no relationship) and display on view

I'm new to laravel and I can't seem to display a data from another table that is not related. I have three tables, Department, Section and Position.
Department Has Many Section
Section Has Many Position
I want to display the department name from the Department table in the position view.
Position Controller
$getPositionWithSection = PositionModel::with('section')->get();
return view('PositionView.add', compact('getPositionWithSection'));
Position View HTML
#foreach($getPositionWithSection as $id => $employee)
<tr>
<td>{{ ++$id }}</td>
<td>{{ $employee->section->department_name }}</td>
<td>{{ $employee->section->section_name }}</td>
<td>{{ $employee->position_name }}</td>
</tr>
#endforeach
I was able to display the name of the section, but how do I display the name of the department?
#foreach($getPositionWithSection as $id => $employee)
<tr>
<td>{{ ++$id }}</td>
<td>{{ $employee->section->department->department_name}}</td>
<td>{{ $employee->section->section_name }}</td>
<td>{{ $employee->position_name }}</td>
</tr>
#endforeach

Generate a 2.500k pages PDF

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.

Trying to access to array in view return Trying to get property of non-object

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

Laravel function to blade

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.

Categories