Thursday, May 17, 2018

RelationNotFoundException Call to undefined relationship [userStories] on model [AppUser] - development

RelationNotFoundException Call to undefined relationship [userStories] on model [AppUser]

I have created a relationship between User model and StoryModel. But it give me the Error

Call to undefined relationship [userStories] on model [AppUser].

May by i am missing something. Following is my code which i am using

Error:
enter image description here

User.php

<?php

namespace App;

use IlluminateNotificationsNotifiable;
use IlluminateFoundationAuthUser as Authenticatable;
use AppNotification;
use AppCheckIn;
use AppTravel;
use CarbonCarbon;
use AppNewInterest;
use AppUserStory;

class User extends Authenticatable
{
    use Notifiable;
    protected $table = "users";
    protected $primaryKey = 'id';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'firstname','lastname', 'user_id','email',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function userStories(){
        return $this->hasMany(UserStory::class, 'user_id', 'user_id');
    }
}

Controller Logic

$usersStories = User::with('userStories')
                            ->select('id','user_id','stories')
                            ->get();
 print_r($usersStories);
    exit;

Any initiative to help will be most appreciated. Thanks



from Laravel Questions and Answers https://laravelquestions.com/php/relationnotfoundexception-call-to-undefined-relationship-userstories-on-model-appuser/
via Lzo Media

No comments:

Post a Comment