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

Comments

Popular posts from this blog

ng-include of inline SVG does not display gradient except in Chrome

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development

ng-show doesn’t work correct with value boolean