Wednesday, January 31, 2018

Laravel relationships changing table columns makes undefined property - development

Laravel relationships changing table columns makes undefined property

So I changed the name of a column in my Laravel app and the party started..

The change was from name_id to seller_id

Before in view:

$transaction->user->first_name

Before in controller Transaction:

class Transaction extends Model
{
    public function user(){
        return $this->belongsTo('AppUser');
    }
 }

After in view:

$transaction->seller->first_name

After in controller Transaction:

class Transaction extends Model
{
    protected $primaryKey = 'seller_id';

    public function user(){
        return $this->belongsTo('AppUser');
    }
}

After returns:

Trying to get property of non-object

For reference the table users has the standard name “user_id”

What I’m doing wrong?



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-relationships-changing-table-columns-makes-undefined-property/
via Lzo Media

No comments:

Post a Comment