Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bacio001's avatar

Equivalent Relations working in development but not in production

Hello everyone,

I'm encountering an issue with the $bot->tags function in my code. In the development environment, it works perfectly fine, but when I deploy it to production, it returns an empty result. I have verified that the data should be filled, so I'm certain that the issue lies elsewhere.

Here is my model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Bot extends Model
{
    use HasFactory;

    protected $guarded = [];

    
    public function tags()
    {
        return $this->hasMany(BotTag::class, 'bot_id', 'id');
    }

    public function users()
    {
        return $this->hasMany(BotUser::class, 'bot_id', 'id');
    }

    public function lister()
    {
        return $this->hasOne(User::class, 'id', 'author');
    }

}

So far I'v tried to change my database Engine to innoDB.

Thanks a lot!

0 likes
14 replies
jlrdw's avatar

Do a little troubleshooting using a combination of dd and the web developer tools. This usually helps me find problems.

bacio001's avatar

@jlrdw the thing is it works on development and I have used those tools it is empty even though it shouldn't be

bacio001's avatar

@krisi_gjika doesn't seem to be it got straight of development copied the database and filled it like I did on production. I saw some posts about issues with db engine but I already changed that to innoDB

bacio001's avatar

@jlrdw I have and it did not fix it I found out that

$bot->tags()->create() works

but

$bot->tags->create()

doesn't, also

$bot->tags->count()

Does not work

$bot->tags()->count()

Does not work

count($bot->tags())

Does not work

So I'm confused on how to fix this sometimes it seems to work and sometimes it doesn't. mean while perfectly fine on local

bacio001's avatar

$bot->tags()->count() does work in my controller but not in the view

In the controller it gives 3 which is correct in the model it gives 0

Snapey's avatar

how did you deploy the project?

bacio001's avatar

@Snapey It is hosted on a CPanel, the service I is called Novonode.

I'v been developing Laravel website for about 4 years now and have always used their hosting, then again I'v never had these issues before with laravel.

Snapey's avatar

@bacio001, yes but how did you deploy?

I didn't ask what type of hosting. Ok, so cpanel. any command line access?

bacio001's avatar

@Snapey Sadly not so far I'v just been using Artisan calls to run commands.

jlrdw's avatar

@bacio001 First thing then is make sure laravel is setup correctly and point to public as document root. And properly setup a server either apache or nginx.

Read the deployment chapter from the laravel documentation.

bacio001's avatar

@jlrdw I agree I should switch to such a server but I bever had a reason since the current host is really cheap and I'v been using it for a while.

Also the website runs well except for the relations stuff, so I'm not sure what part of the setup would be wrong.

You think the host could be the problem?

bacio001's avatar

Thanks for all the replies but I found the issue since the id's are String I had to cast it to a string.

Please or to participate in this conversation.