Laravel Relation One to Many (Polymorphic)

Posted 3 months ago by ravipw1801

Am making a laravel project, Admins & Executives an assign jobs to designers.

Below is the Admin model: Admin.php

public function jobs()
        return $this->hasMany('App\Job');

    public function assignable()
        return $this->morphTo();


public function assignor()
        return $this->belongsTo('App\Assignor','assignable');

    public function designer()
        return $this->belongsTo('App\Designer');

    public function jobStatus()
        return $this->hasOne('App\JobStatus');

    public function client()
        return $this->belongsTo('App\Client');


public function Jobs()
        return $this->hasMany('App\Jobs');

    public function Executive()
        return $this->morphOne('App\Executive','executable');

Jobs Table

Schema::create('jobs', function (Blueprint $table) {


When i tinker the query $admin->jobs

It shows me this error Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'jobs.admin_id' in 'where clause' (SQL: select * fromjobswherejobs.admin_id= 1 andjo bs.admin_idis not null)'

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.