Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

One option is to use a getter which is just a method that returns the value of a property

0

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.

0

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
0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

crazyjoery crazyjoery Joined 19 Aug 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.