Code Monkey home page Code Monkey logo

Comments (4)

staudenmeir avatar staudenmeir commented on August 16, 2024

Hi @mokhosh,
Have you compared the executed queries of $user->products()->get() vs. $user->products?

Does the users table have a column named products by any chance?

from eloquent-has-many-deep.

mokhosh avatar mokhosh commented on August 16, 2024

This is the query for products()->get():

select `products`.*, `purchases`.`user_id` as `laravel_through_key` from `products` inner join `product_purchase` on `product_purchase`.`product_id` = `products`.`id` inner join `purchases` on `purchases`.`id` = `product_purchase`.`purchase_id` where `purchases`.`user_id` = 1;

and this is the one for products property:

select `products`.*, `cart_product`.`cart_id` as `pivot_cart_id`, `cart_product`.`product_id` as `pivot_product_id`, `cart_product`.`quantity` as `pivot_quantity` from `products` inner join `cart_product` on `products`.`id` = `cart_product`.`product_id` where `cart_product`.`cart_id` = 1

I don't have products field on users table.

from eloquent-has-many-deep.

staudenmeir avatar staudenmeir commented on August 16, 2024

Please share the whole User model.

from eloquent-has-many-deep.

mokhosh avatar mokhosh commented on August 16, 2024

🤦‍♂️

I started removing irrelevant code from the model to share it here and I found this:

public function getProductsAttribute()
{
    return $this->cart->products;
}

Sorry for taking your time. Thanks!

from eloquent-has-many-deep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.