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.
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 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.
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 am rendering view in mail template but in my view I am getting following error when I use dd($row['product_name']);. I get product name but not in following code don't know meaning of this error:
#foreach ($order as $row)
<tr>
<td>{{ $row['product_name'] }}</td>
<td>{{ $row['amount'] }}</td>
<td>{{ $row['quantity'] }}</td>
</tr>
#endforeach
getting error:
Illegal string offset 'product_name'
$order is an object $row->product_name and not an array $row['product_name'].
#foreach ($order as $row)
<tr>
<td>{{ $row->product_name }}</td>
<td>{{ $row->amount }}</td>
<td>{{ $row->quantity }}</td>
</tr>
#endforeach
It might be because of 'product_name' key is not exist in your array element. Before using it, check is that key exist in that array element with isset
#foreach ($order as $row)
<tr>
<td>{{ isset($row['product_name'])?$row['product_name']:'' }}</td>
</tr> #endforeach
Try this one:
#foreach ($order as $row)
<tr>
<td>{{ $row->product_name }}</td>
<td>{{ $row->amount }}</td>
<td>{{ $row->quantity }}</td>
</tr>
#endforeach
Check out the laravel documentation for blade https://laravel.com/docs/5.6/blade
Can you try this solution
#foreach ($order as $row)
<tr>
<td>{{ $row->product_name }}</td>
<td>{{ $row->amount }}</td>
<td>{{ $row->quantity }}</td>
</tr>
#endforeach
add dd($row) insted of dd($row['product_name']).
Your Controller returns Object not Array so you try like that
#foreach ($order as $row)
<tr>
<td>{{ $row->product_name }}</td>
<td>{{ $row->amount }}</td>
<td>{{ $row->quantity }}</td>
</tr>
#endforeach
$order is an object you can not use it like an array
#foreach ($order as $row)
<tr>
<td>{{ $row->product_name }}</td>
<td>{{ $row->amount }}</td>
<td>{{ $row->quantity }}</td>
</tr>
#endforeach
If you want to to use the record like this then you need to convert the object toArray()
$order = $order->toArray();
After that you can use like this: $row['product_name']
here $order is an object so you cant use like $row['product_name'].you can use the property of an object using -> operator. so try like this
#foreach ($order as $row)
<tr>
<td>{{ $row->product_name }}</td>
<td>{{ $row->amount }}</td>
<td>{{ $row->quantity }}</td>
</tr>
#endforeach