mardi 20 août 2019

(Laravel 5.4) Call to undefined method Illuminate\Database\Query\Builder::mortphTo()

I have this problem with Laravel 5.4 eloquent's polymorphic relationship where my post comments may belong to either Guest or a User model

users

id | name | username| email | password | bio

guests

id | name | email | website

comments

id | body | user_id | user_type | commentable_id | commentable_type

I can call $user->comments and $guest->comments but if in reverse $comment->user error shows

(1/1) BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::mortphTo()

here is my User model

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    public function comments(){
        return $this->morphMany('App\Comment', 'user');
    }

}


Guest model

namespace App;

use Illuminate\Database\Eloquent\Model;

class Guest extends Model
{
    public function comments(){
        return $this->morphMany('App\Comment', 'user');
    }
}


Comment Model

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    public function user(){
        return $this->mortphTo();
    }
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31TXJKX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire