Support the ongoing development of →
Database Eloquent
Last updated 1 year ago.

Have you set theme_code as the primary key of Theme model?


No. Do I need to do that?


Sorry, I've read your code wrong. What's the schema for themes table? Is code primary key of themes table?


Yes it is. code is the primary key for themes table and id is the primary key for the users table. the pivot table theme_user has user_id and theme_code as columns


Eloquent assumes the name of primary key is id, in your case you need to specify primary key for Theme model explicitly:

class Theme extends Model 
    protected $primaryKey = 'code';

Sign in to participate in this thread!


Your banner here too?

reshadf reshadf Joined 4 Mar 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.