'LOG.error: Property [reff_code] does not exist on this collection instance
I can't display the whole data in a table in Laravel 8. Every time I pull data, it always comes out limit 1 sentence, but when I want to change get() to first() it always fails.
LOG.error: Property [reff_code] does not exist on this collection instance. {"userId":8,"exception":{}}
Model
class LRD extends Model
{
use HasFactory;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $table = "lrd";
protected $fillable = [
'used', 'lrd_code', 'remaining', 'requester', 'approver1',
'approver2', 'approver3', 'leadtime', 'bu_code', 'account_name',
'status', 'detail', 'reff_code', 'created_at', 'updated_at'
];
public function fpd()
{
return $this->belongsTo(FPD::class);
}
}
View
<table>
<tr>
<th class="text-center" style="border: 1px solid; padding: 10px; width: 10%">#
</th>
<th class="text-center" style="border: 1px solid; padding: 10px; width: 20%">
Account Name
</th>
<th class="text-center" style="border: 1px solid; padding: 10px; width: 20%">
Amount
</th>
<th class="text-center" style="border: 1px solid; padding: 10px; width: 20%">
Used
</th>
</tr>
<tr>
<td class="text-center" style="border: 1px solid; padding: 10px;">
<input type="checkbox">
</td>
<td class="text-center" style="border: 1px solid; padding: 10px;">
{{ $data->account }}
</td>
<td class="text-center" style="border: 1px solid; padding: 10px;">
Rp{{ number_format($data->amount, 2, '.', '.') }}
</td>
<td class="text-center" style="border: 1px solid; padding: 10px;">
Rp{{ number_format($data->ussed, 2, '.', '.') }}</td>
</tr>
</table>
Controller
public function createPDF(Request $request, $code)
{
$select = [
'lrd.*',
'u.username',
'u.name as name_users',
'acc_fpd.*',
'acc_fpd.fpd_code',
'acc_fpd.account_name as account',
'acc_fpd.amount as amount',
'acc_fpd.used as ussed'
];
$data = DB::table('lrd')
->select($select)
->leftJoin('users as u', 'u.id', '=', 'lrd.id_requester')
->join('fpd', 'lrd.reff_code', '=', 'fpd.fpd_code')
->join('acc_fpd', 'fpd.fpd_code', '=', 'acc_fpd.fpd_code')
->where('lrd_code', $code)
->get();
if (!$data) {
return $this->sendError(2, 'LRD Not Found', []);
}
$account = DB::table('acc_fpd')
->where('fpd_code', $data->reff_code)->get();
$user_bu = getUsersBU();
$select = [
'fpd.*',
'bu.bu_code',
'bu.bu_name'
];
$fpd = DB::table('fpd')
->select($select)
->leftJoin('business_units as bu', 'bu.id', '=', 'fpd.bu_id')
->where('fpd_code', $data->reff_code)
->whereIn('bu_code', $user_bu)
->first();
$data->bu_name = $fpd->bu_name;
$manager = explode(" ", $data->approver1);
$finance = explode(" ", $data->approver2);
$cashier = explode(" ", $data->approver3);
$data->manager = "-";
$data->manager_date = "";
if (count($manager) == 2) {
$data->manager = $manager[0];
$data->manager_date = $manager[1];
}
$data->finance = "-";
$data->finance_date = "";
if (count($finance) == 2) {
$data->finance = $finance[0];
$data->finance_date = $finance[1];
}
$data->cashier = "-";
$data->cashier_date = "";
if (count($cashier) == 2) {
$data->cashier = $cashier[0];
$data->cashier_date = $cashier[1];
}
checkStorageDir('export', 'lrd');
$name = $code.'.pdf';
$path = 'export'.DIRECTORY_SEPARATOR.$name;
$filePath = (storage_path('app/public'.DIRECTORY_SEPARATOR.'lrd'.DIRECTORY_SEPARATOR).$path);
$url = asset('storage/lrd/'.$path);
$pdf = PDF::loadview('export.lrd', compact('data'))->setPaper('A4', 'potrait');
$pdf->save($filePath);
$result = (object) array();
$result->code = $code;
$result->path = $path;
$result->name = $name;
$result->pdf_path = asset('storage/lrd/'.$path);
if (!empty($result)) {
return Response::json([
'success' => true,
'data' => $result
], 200);
} else {
return Response::json([
'success' => false
], 400);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
