@snapey
What i meant was to store as an BigInteger
Something like this
E.g. -
Qty : 10,000
Rate : $3.838
Total : $38,838
public function getBillItemRateAttribute($rate)
{
return $rate / 10000;
}
public function setBillItemRateAttribute($value)
{
$this->attributes['rate'] = $value * 10000;
}
In this case 38380 will be stored in the database under the rate field
I think this approach should be ok
Now my issue is dealing with pivot tables
E.g.
Invoice Class
public function subJobs()
{
return $this->belongsToMany('App\Models\SubJob', 'invoice_subjob', 'invoice_id', 'subjob_id')
->withPivot('id', 'invoice_id', 'subjob_id', 'qty', 'rate', 'description')
->withTimestamps();
}
SubJob Class
public function invoices()
{
return $this->belongsToMany('App\Models\Invoice', 'invoice_subjob')
->withPivot('id', 'invoice_id', 'subjob_id', 'name', 'qty', 'rate', 'description')
->withTimestamps();
}
invoice_subjob is the pivot table
Then when i need to do something like this
@foreach ($invoice->subJobs as $subJob)
<tr>
<td class="px-6 py-2 text-sm text-center text-gray-500 border-2 border-gray-200 whitespace-nowrap">
{{ $subJob->name }}
</td>
<td class="px-6 py-2 text-sm text-center text-gray-500 border-2 border-gray-200 whitespace-nowrap">
{{ $subJob->pivot->description }}</b>
</td>
<td class="px-6 py-2 text-sm text-center text-gray-500 border-2 border-gray-200 whitespace-nowrap">
{{ $subJob->pivot->qty }}
</td>
<td class="px-6 py-2 text-sm text-center text-gray-500 border-2 border-gray-200 whitespace-nowrap">
{{ $subJob->pivot->rate }}
</td>
<td class="px-6 py-2 text-sm text-center text-gray-500 border-2 border-gray-200 whitespace-nowrap">
{{ ($subJob->pivot->qty * $subJob->pivot->rate) }}
</td>
<td class="px-6 py-2 text-sm text-center text-gray-500 border-2 border-gray-200 whitespace-nowrap">
</td>
</tr>
@endforeach
How can i apply the accessor to
{{ $subJob->pivot->rate }}
Something like this is required
public function getRateAttribute($rate)
{
return $rate / 10000;
}