I'm trying to create a package where i can put all my blade components. So i can include my repo in all my future applications, and the only thing i have to do is update this single package instead of copy paste all new code to all my applications.
At this point, the component class is being loaded but the template is not found. I ran out of ideas how to load my blade templates. This is my setup.
O, and i don't want to publish the templates, because that would mean i should run an extra command for each application i want to update.
I hope someone can see thru my stupidity and point out what i'm doing wrong. Thanks in advance
Textarea Component
<?php
namespace PHPieter\LB4C\View\Components\Form;
use Illuminate\View\Component;
class Textarea extends Component
{
public ?string $name;
public function __construct(?string $name = null)
{
$this->name = $name;
}
public function render()
{
return view('components.form.customtextarea');
}
}
PackageServiceProvider
<?php
namespace PHPieter\LB4C;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use PHPieter\LB4C\View\Components\Form\Textarea;
class LibraryServiceProvider extends ServiceProvider
{
/** @var string */
private const CONFIG_FILE = __DIR__ . '/../config/library.php';
/** @var string */
private const PATH_VIEWS = __DIR__ . '../resources/views/';
/**
* Register the application services.
*
* @return void
*/
public function register(): void
{
$this->mergeConfigFrom(self::CONFIG_FILE, 'library');
}
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(): void
{
$this->loadViewsFrom(realpath(self::PATH_VIEWS), 'laravel-components-library');
Blade::component(Textarea::class,'customtextarea' );
}
}
My blade component is located at: resources/views/components/form/customtextarea.blade.php