Skip to content

Instantly share code, notes, and snippets.

@jjcodes78
Last active June 11, 2021 05:00
Show Gist options
  • Save jjcodes78/1e1916d4aa9d77f43fafb4a5b5462f1a to your computer and use it in GitHub Desktop.
Save jjcodes78/1e1916d4aa9d77f43fafb4a5b5462f1a to your computer and use it in GitHub Desktop.
Registering anonymous blade components from a package

How to

<?php

public function boot()
{
  $dir = resource_path(<views-folder>);
  $this->loadViewsFrom($dir, '<prefix>');

  foreach (scandir($dir) as $file) {
      if(str_contains($file, ".blade")) {
          $component = str_replace(".blade.php", "", $file);
          Blade::component("package-name::$component", $component, '<component-prefix>');
      }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment