-2

I want to fetch only the specific column seller_db from seller table with the help of model, but when i used this below code my relationship shows null value, please help me to find my mistake, and how can i fetch selected one field with model using laravel?

here is my User.php file.

User.php


    public function sellerDB()
        {
            $instance = $this->hasOne('\App\Seller', 'user_id', 'id')->select('seller_db');
            return $instance;
        }

1 Answers1

0

Edit: I made a mistake, I misunderstood your database design, it's necessary add an aditional method to resolve this:

    public function seller()
    {
        return $this->hasOne('\App\Seller', 'user_id', 'id')
    }

    public function sellerDB()
    {
        return $this->seller->seller_db;
    }

In this case you can call $user->sellerDB() and receive the column seller_db