Morph Relation #662
Replies: 1 comment
-
Sorry, This forum is for backpack-related queries only. Check if the following resource helps. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Good morning,
i have an error in polimorphic relation:
I have 3 models:
class Producer extends Model
{
public function user(): MorphOne
{
return $this->morphOne(User::class, 'userable');
}
class Judge extends Model
{
public function user(): MorphOne
{
return $this->morphOne(User::class, 'userable');
}
class User extends Authenticatable
{
public function userable(): MorphTo{
return $this->MorphTo(FUNCTION, 'userable_type', 'userable_id');
}
my migration:
Schema::table('users', function (Blueprint $table) {
$table->morphs('userable');
});
when i call:
\App\Models\User::find(2)->userable
if user havent any model related (userable_id and userable_type is empty) i get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.' in 'where clause' (SQL: select * from
users
whereusers
.`` = 0 andusers
.`deleted_at` is null limit 1).why?
can someone help me?
tanks
Beta Was this translation helpful? Give feedback.
All reactions