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

michael.simso's avatar

Laravel Blade component method undefined in production but work in local dev

I have a component NoteTag in app/View/Components/Notes and the blade component in resources/views/components/notes.

I am using this component in a parent component like this:

<x-notes.note-tag :name="$tag->name"></x-notes.note-tag>

NoteTag has a method which I want to use in the view:

    public function typeColor()
    {
        return substr(md5($this->name), 0, 6);
    }

I reference the method in the view like this:

<span style="border: 2px #{{ $typeColor() }} solid" class="rounded-lg mr-2 px-1 bg-gray-200 text-gray-600 shadow">
    {{ $name }}
</span>

This works great in local development, but in production i get this:

[previous exception] [object] (ErrorException(code: 0): Undefined variable $typeColor at /home/forge/loggbok.michaelsimsoe.no/storage/framework/views/e354b32f864ce675974b798281d94fe7f4dd2831.php:1)
[stacktrace]

I've also tried to pass it to the view as data:

    public function render()
    {
        return view('components.notes.note-tag', ['color' => $this->typeColor()]);
    }

Which results in the same error. So I guess there is some mapping issue in production where the component view cant fin the class.

As per https://github.com/laravel/framework/issues/31919 and Laravel docs: Manually Registering Components I've tried this in the AppServiceProvider:


use App\View\Components\Notes\NoteTag;
use Illuminate\Support\Facades\Blade;

...

class AppServiceProvider extends ServiceProvider
{

    ...

    public function boot()
    {
        Blade::component('note-tag', NoteTag::class);
    }

    ...

With no luck.

I've seen multiple mentions of this problem:

Some mention the casing of the class name as an issue. Some mention the manually registering of components. None of them works for me.

I'm using Forge to host the app on DigitalOcean.

I'm using the latest version of Laravel and PHP 8.

The repo for the application

The folder structure in app The folder structure of my views

Any ideas?

0 likes
1 reply
michael.simso's avatar
michael.simso
OP
Best Answer
Level 7

Stack overflow to the rescue: Answer

I had changed the filename of my NoteTag class from noteTag to _NoteTag` locally but it hadn't been commited to git and thereby not to production. The missing capital N apparently caused Laravel to not find the Class.

All good now.

Please or to participate in this conversation.