One option is to use a getter which is just a method that returns the value of a property
i basicly use a trait to get alot of price information from the database. I would like to return the prices from the trait so i can use them in a controller.
i'm not quite sure how your trait looks like, is the first code block the trait method ?
you can create a getContractValueAttribute method on your BuiOreContractContents model:
public function getContractValueAttribute()
{
// return calculated value
}
usage
$oreContract->ContractValue //returns calculated value
Here is the first code block for the trait.
trait Contracts
{
use Prices;
public function OreContract(Request $request)
{
$update = BuiOrePrices::orderBy('created_at', 'desc')->first();
$lastContractNum = BuiContracts::max('ContractNum');
$oreContract = new BuiOreContractContents();
$ContractNum = $lastContractNum + 1;
$oreContract->ContractNum = $ContractNum;
$oreContract->QuoteTime = $update['created_at'];
if($request['Veldspar_units'])
{$oreContract->Veldspar = $request['Veldspar_units'];} else {$oreContract->Veldspar = '0';}
Prices is another trait i've setup to pull prices from the database. Hopefully this helps a bit
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community