Welcome Guest, Not a member yet? Register   Sign In
How to return calculated from model?
#1

(This post was last modified: 03-17-2022, 08:40 AM by frocco.)

Hello, not sure where to put this.

I have a database table that has several price fields, price1, price2...

After I query the table, I want to access the price field that would be one of those.

The price should be returned as one of the price1, price2 fields.

I tried defining getPrice in the entity class, but get an error when I try to access it using $product->price

Can someone help me with this?

PHP Code:
$data['products'] = $this->product
            
->select('products.id,name,sku,image,image2,image3,cat_pic,stock,utqg,warranty,price')
            ->
join('categories''categories.id = products.category_id')
            ->
where('is_featured'1)
            ->
where('is_active'1)
            ->
where('stock >'0)
            ->
orderBy("stock desc")
            ->
paginate(25); 

Unknown column 'price' in 'field list'
Reply
#2

The only way I see to get this working is to rename the categories primary key id to cat_id

Then I can remove the ->select('products.id,name,sku,image,image2,image3,cat_pic')
statement and reference $products->price that is defined in the entity class.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB