Column not found in laravel polymorphic relationship
<p>developers :)</p>

<p>I'm made a relationship (many-to-many polymorphic) in laravel </p>

<p>between :</p>

<ul>
<li> users </li>
<li> clothes , shoes , ...ect (each one is a model on it's own )
</li>

</ul>

<p><strong>hint:</strong> the user can favorite any one he like (clothes or shoes ...etc)</p>

<p><strong>user model :</strong></p>

<pre><code>class User extends Authenticatable
{
public  function  clothes()
    {

        return $this-&gt;morphToMany('Etrade\clothes\Clothes' ,'favoritable' )
       -&gt;withTimestamps('created_at','updated_at');

    }
}
</code></pre>

<p><strong>clothes model :</strong></p>

<pre><code>class Clothes extends Model
{

 // relationship with user
    public  function  user()
    {
        return $this-&gt;morphToMany('Etrade\Users\User' ,'favoritable')
       -&gt;withTimestamps('created_at','updated_at');
    }

}
</code></pre>

<p><strong>favoritable model :</strong></p>

<pre><code>class Favriable extends Model
{
    protected $table = 'favoritables';

    public function favoritable()
    {
        return $this-&gt;morphTo();
    }
}
</code></pre>

<p><strong>fetching the data using relationship :</strong></p>

<p><em>- get all users for given clothes :</em></p>

<pre><code>$clo= Etrade\clothes\Clothes::find(35);

$clo-&gt;user; // fetch the relation

=&gt; Illuminate\Database\Eloquent\Collection {#760
     all: [
       Etrade\Users\User {#761
         id: 4,
         name: "Reta Paucek",
         email: "ahegmann@example.org",
         gender: 0,
         mobile: "",
         city_id: 0,
         active: 0,
         friend_status: 1,
         created_at: "2016-12-26 18:53:51",
         updated_at: "2016-12-26 18:53:51",
         pivot: Illuminate\Database\Eloquent\Relations\MorphPivot {#213
           favoritable_id: 35,
           user_id: 4,
           created_at: "2016-12-30 03:34:58",
           updated_at: "2016-12-30 03:34:58",
         },
       },
     ],
   }
</code></pre>

<p><strong>- get all clothes for given user:</strong></p>

<pre><code> $user = Etrade\Users\User::find(4);

 $user-&gt;clothes; // fetch the relationship
</code></pre>

<p><strong>Getting error :</strong></p>

<pre><code>Column not found: 1054 Unknown column 'favoritables.clothes_id' in 'field list' (SQL: select
`clothes`.*, `favoritables`.`favoritable_id` as `pivot_favoritable_id`, `favoritables`.`clothes_id` as `pivot_clothes_id`, `favoritables`.`created_at` as `pivo
t_created_at`, `favoritables`.`updated_at` as `pivot_updated_at` from `clothes` inner join `favoritables` on `clothes`.`id` = `favoritables`.`clothes_id` where
 `favoritables`.`favoritable_id` = 4 and `favoritables`.`favoritable_type` = Etrade\Users\User)'
</code></pre>

<p><strong>My question :</strong> how to fix this error ,,, the relationship work in one direction not for both ??</p>