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

finalblast's avatar

registering your Components inside a Service Provider's boot method

I have a question. By following documentation on https://laravelcollective.com/docs/5.2/html#custom-components I create a blade contains my form at the same direction. I want to know how to register my components in the Service Provider. "You might consider registering your Components inside a Service Provider's boot method." Please help me. Thank so much.

0 likes
12 replies
bobbybouwmann's avatar
Level 88

It just means that you need to create a new service provider and then add the component in the boot method, and finally register the service provider in your application

php artisan make:provider FormServiceProvider

Then update the boot method of that class

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class FormServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        // Register the form components
        Form::component('bsText', 'components.form.text', ['name', 'value', 'attributes']);
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        // We have nothing to register, so we leave this blank
    }
}

And finally register the service provider in config/app.php

'providers' => [
    
    // Other providers

    App\Providers\FormServiceProvider::class,

],
1 like
cliftonscott's avatar

When I try this, I receive a "Class 'App\Providers\Form' not found" error inside on FormServiceProvider.php

d3xt3r's avatar

"Class App\Providers\Form not found"

Is a clear indication of what going wrong. Remember to import the classes that you are using, for global namespace use \

1 like
d3xt3r's avatar

I am not here to argue on that, just that debugging is equally important as coding. So start paying attention to what error messages / exceptions have to say ...

cliftonscott's avatar

Thank you for your passive-aggressive help.

Anyone else bumps into this, the use Form block is missing.

use Form;
1 like
PaulH's avatar

I've tried the offered solution, but run into this error:

ErrorException in FileViewFinder.php line 137: View [components.form.text] not found.

When i remove the {{ Form::bsText('updated_at') }} -line it works fine.

{{ Form::text('created_at') }} works, so laravelcollective/html seems toe be working.

Clearing caches ect doesn't help. I'm running Laravel 5.3.31

Any insights? Do i need to store a file (components.form.text) somewhere perhaps? Since FileViewFinder is throwing the error.

Cvetan's avatar

I am trying to make custom component. I did register it in new service provider, registered provider. But when I try to use it with: {{ Form::bsText('testName') }} I get the following error: Call to undefined method Collective\Html\FormFacade::component(). Do you know what could be the issue?

Cvetan's avatar

OK, guys sorry I made mistake. I didn't see I implemented in register method and not in boot. :)

1 like

Please or to participate in this conversation.