Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel Blade says it cannot find a class or view for a component

ErrorUnable to locate a class or view for component [alert].

Short answer

Blade finds your own components only in app/View/Components and resources/views/components. If the tag x-name has no matching class or view there, it fails. Check the file name against the kebab-case tag, use a dot for each subfolder, and register package components yourself with Blade::component or Blade::componentNamespace.

  • Applies to Laravel 12, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the places Blade auto-discovers components in, and look for the one named in the error.

    ls app/View/Components
    find resources/views/components -name "*.blade.php"
  2. 2Match what you see, then jump to its fix

    1. 1The component tag is x-alert but no Alert class and no components/alert.blade.php existThe class or view is not in a discovered folder, or its name does not match the tagFix
    2. 2The file is app/View/Components/Forms/Input.php, and the tag is x-inputThe component sits in a subfolder, but the tag does not use dotsFix
    3. 3The class exists, but not under app/View/ComponentsThe component comes from a package or another folder and was never registeredFix

What does the error look like?

  • Unable to locate a class or view for component [alert].
  • InvalidArgumentException: Unable to locate a class or view for component

Cause 1 of 3

The class or view is not in a discovered folder, or its name does not match the tag

1Check

Class components are auto-discovered under app/View/Components and their views under resources/views/components. Tags use the kebab-case form of the class name, so Alert is x-alert.

ls app/View/Components resources/views/components

2Fix

Create the component with Artisan so both files land in the right place, or move your files there.

php artisan make:component Alert
# anonymous, view only:
php artisan make:component alert --view

3Verify

Render the tag in a view, for example <x-alert />, and reload the page.

ls app/View/Components/Alert.php resources/views/components/alert.blade.php

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The component sits in a subfolder, but the tag does not use dots

1Check

For a component nested deeper, the tag uses a dot for each folder level.

find app/View/Components resources/views/components -mindepth 2

2Fix

Write the tag with the folder path, for example x-forms.input.

<x-forms.input />

3Verify

Reload the page that used the tag.

ls resources/views/components/forms/input.blade.php

Confirmed by laravel.com

Did this fix it?

Cause 3 of 3

The component comes from a package or another folder and was never registered

1Check

Only the two default folders are discovered. A package must register its components in its service provider.

grep -rn "Blade::component" app/ vendor/<vendor>/<package>/src 2>/dev/null

2Fix

Register one component by name, or a whole namespace by convention.

// service provider boot()
Blade::component('package-alert', AlertComponent::class);

// or a whole namespace, used as <x-nightshade::calendar />
Blade::componentNamespace('Nightshade\\Views\\Components', 'nightshade');

3Verify

Use the registered tag in a view.

<x-package-alert />

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Create components with php artisan make:component rather than by hand, so both files are placed correctly.
  • Keep one folder level per dot in the tag, and keep file names in line with the kebab-case tag.
  • Register package components in the package's service provider.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.