Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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

0

No. Do I need to do that?

0

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

0

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

0

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';
    ...
0

Sign in to participate in this thread!

Eventy

Your banner here too?

reshadf reshadf Joined 4 Mar 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.