init laravel-modules-template

This commit is contained in:
2025-06-03 10:55:05 +08:00
commit d286093f3e
158 changed files with 11171 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function __invoke() {}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function handle() {}
}

View File

View File

View File

@ -0,0 +1,25 @@
<?php
namespace $CLASS_NAMESPACE$;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
class $CLASS$ implements CastsAttributes
{
/**
* Cast the given value.
*/
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}
/**
* Prepare the given value for storage.
*/
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return $value;
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace $NAMESPACE$;
class $CLASS$
{
/**
* Create a new channel instance.
*/
public function __construct() {}
/**
* Authenticate the user's access to the channel.
*/
public function join(Operator $user): array|bool {}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $NAMESPACE$;
class $CLASS$
{
public function __invoke() {}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $NAMESPACE$;
class $CLASS$
{
public function __construct() {}
}

View File

@ -0,0 +1,53 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class $CLASS$ extends Command
{
/**
* The name and signature of the console command.
*/
protected $signature = '$COMMAND_NAME$';
/**
* The console command description.
*/
protected $description = 'Command description.';
/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle() {}
/**
* Get the console command arguments.
*/
protected function getArguments(): array
{
return [
['example', InputArgument::REQUIRED, 'An example argument.'],
];
}
/**
* Get the console command options.
*/
protected function getOptions(): array
{
return [
['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
];
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace $NAMESPACE$;
use Illuminate\View\Component;
use Illuminate\View\View;
class $CLASS$ extends Component
{
/**
* Create a new component instance.
*/
public function __construct() {}
/**
* Get the view/contents that represent the component.
*/
public function render(): View|string
{
return view('$LOWER_NAME$::$COMPONENT_NAME$');
}
}

View File

@ -0,0 +1,3 @@
<div>
<!-- $QUOTE$ -->
</div>

View File

@ -0,0 +1,30 @@
{
"name": "$VENDOR$/$LOWER_NAME$",
"description": "",
"authors": [
{
"name": "$AUTHOR_NAME$",
"email": "$AUTHOR_EMAIL$"
}
],
"extra": {
"laravel": {
"providers": [],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": "$APP_FOLDER_NAME$",
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Database\\Factories\\": "database/factories/",
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\Tests\\": "tests/"
}
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace $CLASS_NAMESPACE$;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class $CLASS$ extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
return response()->json([]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
return response()->json([]);
}
/**
* Show the specified resource.
*/
public function show($id)
{
//
return response()->json([]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
return response()->json([]);
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
return response()->json([]);
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace $CLASS_NAMESPACE$;
use Illuminate\Routing\Controller;
class $CLASS$ extends Controller {}

View File

@ -0,0 +1,17 @@
<?php
namespace $CLASS_NAMESPACE$;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class $CLASS$ extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request)
{
return response()->json([]);
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace $CLASS_NAMESPACE$;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class $CLASS$ extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('$LOWER_NAME$::index');
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('$LOWER_NAME$::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request) {}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('$LOWER_NAME$::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('$LOWER_NAME$::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id) {}
/**
* Remove the specified resource from storage.
*/
public function destroy($id) {}
}

View File

@ -0,0 +1,5 @@
<?php
namespace $CLASS_NAMESPACE$;
enum $CLASS$ {}

View File

@ -0,0 +1,27 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class $CLASS$ extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*/
protected function configureEmailVerification(): void {}
}

View File

@ -0,0 +1,31 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class $CLASS$
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*/
public function __construct() {}
/**
* Get the channels the event should be broadcast on.
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel-name'),
];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace $CLASS_NAMESPACE$;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class $CLASS$ extends Exception
{
/**
* Report the exception.
*/
public function report(): void {}
/**
* Render the exception as an HTTP response.
*/
public function render(Request $request): Response {}
}

View File

@ -0,0 +1,15 @@
<?php
namespace $CLASS_NAMESPACE$;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class $CLASS$ extends Exception
{
/**
* Render the exception as an HTTP response.
*/
public function render(Request $request): Response {}
}

View File

@ -0,0 +1,13 @@
<?php
namespace $CLASS_NAMESPACE$;
use Exception;
class $CLASS$ extends Exception
{
/**
* Report the exception.
*/
public function report(): void {}
}

View File

@ -0,0 +1,7 @@
<?php
namespace $CLASS_NAMESPACE$;
use Exception;
class $CLASS$ extends Exception {}

View File

@ -0,0 +1,22 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Database\Eloquent\Factories\Factory;
class $NAME$Factory extends Factory
{
/**
* The name of the factory's corresponding model.
*/
protected $model = \$MODEL_NAMESPACE$\$NAME$::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [];
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function __invoke() {}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function handle() {}
}

View File

@ -0,0 +1,5 @@
<?php
namespace $CLASS_NAMESPACE$;
interface $CLASS$ {}

View File

@ -0,0 +1,24 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class $CLASS$ implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct() {}
/**
* Execute the job.
*/
public function handle(): void {}
}

View File

@ -0,0 +1,21 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
class $CLASS$ implements ShouldQueue
{
use Dispatchable, Queueable;
/**
* Create a new job instance.
*/
public function __construct() {}
/**
* Execute the job.
*/
public function handle(): void {}
}

View File

@ -0,0 +1,11 @@
{
"name": "$STUDLY_NAME$",
"alias": "$LOWER_NAME$",
"description": "",
"keywords": [],
"priority": 0,
"providers": [
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\$PROVIDER_NAMESPACE$\\$STUDLY_NAME$ServiceProvider"
],
"files": []
}

View File

@ -0,0 +1,19 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$
{
/**
* Create the event listener.
*/
public function __construct() {}
/**
* Handle the event.
*/
public function handle($event): void {}
}

View File

@ -0,0 +1,21 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$ implements ShouldQueue
{
use InteractsWithQueue;
/**
* Create the event listener
*/
public function __construct() {}
/**
* Handle the event.
*/
public function handle($event): void {}
}

View File

@ -0,0 +1,22 @@
<?php
namespace $NAMESPACE$;
use $EVENTNAME$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$ implements ShouldQueue
{
use InteractsWithQueue;
/**
* Create the event listener.
*/
public function __construct() {}
/**
* Handle the event.
*/
public function handle($SHORTEVENTNAME$ $event): void {}
}

View File

@ -0,0 +1,20 @@
<?php
namespace $NAMESPACE$;
use $EVENTNAME$;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$
{
/**
* Create the event listener.
*/
public function __construct() {}
/**
* Handle the event.
*/
public function handle($SHORTEVENTNAME$ $event): void {}
}

View File

@ -0,0 +1,26 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class $CLASS$ extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct() {}
/**
* Build the message.
*/
public function build(): self
{
return $this->view('view.name');
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace $NAMESPACE$;
use Closure;
use Illuminate\Http\Request;
class $CLASS$
{
/**
* Handle an incoming request.
*/
public function handle(Request $request, Closure $next)
{
return $next($request);
}
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('$TABLE$', function (Blueprint $table) {
$FIELDS_UP$
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('$TABLE$', function (Blueprint $table) {
$FIELDS_DOWN$
});
}
};

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('$TABLE$', function (Blueprint $table) {
$table->id();
$FIELDS$
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('$TABLE$');
}
};

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('$TABLE$', function (Blueprint $table) {
$FIELDS_UP$
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('$TABLE$', function (Blueprint $table) {
$FIELDS_DOWN$
});
}
};

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::dropIfExists('$TABLE$');
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::create('$TABLE$', function (Blueprint $table) {
$table->id();
$FIELDS$
$table->timestamps();
});
}
};

View File

@ -0,0 +1,18 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void {}
/**
* Reverse the migrations.
*/
public function down(): void {}
};

View File

@ -0,0 +1,22 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// use $MODULE_NAMESPACE$\$MODULE$\Database\Factories\$NAME$Factory;
class $CLASS$ extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*/
protected $fillable = $FILLABLE$;
// protected static function newFactory(): $NAME$Factory
// {
// // return $NAME$Factory::new();
// }
}

View File

@ -0,0 +1,45 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class $CLASS$ extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct() {}
/**
* Get the notification's delivery channels.
*/
public function via($notifiable): array
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail($notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', 'https://laravel.com')
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*/
public function toArray($notifiable): array
{
return [];
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace $NAMESPACE$;
use $MODEL_NAMESPACE$\$NAME$;
class $NAME$Observer
{
/**
* Handle the $NAME$ "created" event.
*/
public function created($NAME$ $NAME_VARIABLE$): void {}
/**
* Handle the $NAME$ "updated" event.
*/
public function updated($NAME$ $NAME_VARIABLE$): void {}
/**
* Handle the $NAME$ "deleted" event.
*/
public function deleted($NAME$ $NAME_VARIABLE$): void {}
/**
* Handle the $NAME$ "restored" event.
*/
public function restored($NAME$ $NAME_VARIABLE$): void {}
/**
* Handle the $NAME$ "force deleted" event.
*/
public function forceDeleted($NAME$ $NAME_VARIABLE$): void {}
}

View File

@ -0,0 +1,15 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"axios": "^1.1.2",
"laravel-vite-plugin": "^0.7.5",
"sass": "^1.69.5",
"postcss": "^8.3.7",
"vite": "^4.0.0"
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Auth\Access\HandlesAuthorization;
class $CLASS$
{
use HandlesAuthorization;
/**
* Create a new policy instance.
*/
public function __construct() {}
}

View File

@ -0,0 +1,21 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Support\ServiceProvider;
class $CLASS$ extends ServiceProvider
{
/**
* Register the service provider.
*/
public function register(): void {}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function __invoke() {}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function handle() {}
}

View File

@ -0,0 +1,24 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Foundation\Http\FormRequest;
class $CLASS$ extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class $CLASS$ extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class $CLASS$ extends JsonResource
{
/**
* Transform the resource into an array.
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class $CLASS$ extends ServiceProvider
{
protected string $name = '$MODULE$';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path($this->name, '$WEB_ROUTES_PATH$'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '$API_ROUTES_PATH$'));
}
}

View File

@ -0,0 +1,8 @@
<?php
use Illuminate\Support\Facades\Route;
use $MODULE_NAMESPACE$\$STUDLY_NAME$\$CONTROLLER_NAMESPACE$\$STUDLY_NAME$Controller;
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
Route::apiResource('$PLURAL_LOWER_NAME$', $STUDLY_NAME$Controller::class)->names('$LOWER_NAME$');
});

View File

@ -0,0 +1,8 @@
<?php
use Illuminate\Support\Facades\Route;
use $MODULE_NAMESPACE$\$STUDLY_NAME$\$CONTROLLER_NAMESPACE$\$STUDLY_NAME$Controller;
Route::middleware(['auth', 'verified'])->group(function () {
Route::resource('$PLURAL_LOWER_NAME$', $STUDLY_NAME$Controller::class)->names('$LOWER_NAME$');
});

View File

@ -0,0 +1,19 @@
<?php
namespace $NAMESPACE$;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class $CLASS$ implements ValidationRule
{
/**
* Indicates whether the rule should be implicit.
*/
public bool $implicit = true;
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail): void {}
}

View File

@ -0,0 +1,14 @@
<?php
namespace $NAMESPACE$;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
class $CLASS$ implements ValidationRule
{
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail): void {}
}

View File

@ -0,0 +1,5 @@
<?php
return [
'name' => '$STUDLY_NAME$',
];

View File

@ -0,0 +1,154 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class $CLASS$ extends ServiceProvider
{
use PathNamespace;
protected string $name = '$MODULE$';
protected string $nameLower = '$LOWER_NAME$';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->name, '$MIGRATIONS_PATH$'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->nameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->nameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->name, '$PATH_LANG$'), $this->nameLower);
$this->loadJsonTranslationsFrom(module_path($this->name, '$PATH_LANG$'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$configPath = module_path($this->name, config('modules.paths.generator.config.path'));
if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname());
$config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config);
$segments = explode('.', $this->nameLower.'.'.$config_key);
// Remove duplicated adjacent segments
$normalized = [];
foreach ($segments as $segment) {
if (end($normalized) !== $segment) {
$normalized[] = $segment;
}
}
$key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized);
$this->publishes([$file->getPathname() => config_path($config)], 'config');
$this->merge_config_from($file->getPathname(), $key);
}
}
}
}
/**
* Merge config from the given path recursively.
*/
protected function merge_config_from(string $path, string $key): void
{
$existing = config($key, []);
$module_config = require $path;
config([$key => array_replace_recursive($existing, $module_config)]);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->nameLower);
$sourcePath = module_path($this->name, '$PATH_VIEWS$');
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->nameLower)) {
$paths[] = $path.'/modules/'.$this->nameLower;
}
}
return $paths;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace $CLASS_NAMESPACE$;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class $CLASS$ implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void {}
}

View File

@ -0,0 +1,16 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Database\Seeder;
class $NAME$ extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// $this->call([]);
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function __invoke() {}
}

View File

@ -0,0 +1,8 @@
<?php
namespace $CLASS_NAMESPACE$;
class $CLASS$
{
public function handle() {}
}

View File

@ -0,0 +1,18 @@
<?php
namespace $NAMESPACE$;
use Tests\TestCase;
class $CLASS$ extends TestCase
{
/**
* A basic test example.
*/
public function test_the_application_returns_a_successful_response(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace $NAMESPACE$;
use Tests\TestCase;
class $CLASS$ extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}

View File

@ -0,0 +1,5 @@
<?php
namespace $CLASS_NAMESPACE$;
trait $CLASS$ {}

View File

@ -0,0 +1,3 @@
<div>
<!-- $QUOTE$ -->
</div>

View File

@ -0,0 +1,5 @@
<x-$LOWER_NAME$::layouts.master>
<h1>Hello World</h1>
<p>Module: {!! config('$LOWER_NAME$.name') !!}</p>
</x-$LOWER_NAME$::layouts.master>

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>$STUDLY_NAME$ Module - {{ config('app.name', 'Laravel') }}</title>
<meta name="description" content="{{ $description ?? '' }}">
<meta name="keywords" content="{{ $keywords ?? '' }}">
<meta name="author" content="{{ $author ?? '' }}">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
{{-- Vite CSS --}}
{{-- {{ module_vite('build-$LOWER_NAME$', 'resources/assets/sass/app.scss') }} --}}
</head>
<body>
{{ $slot }}
{{-- Vite JS --}}
{{-- {{ module_vite('build-$LOWER_NAME$', 'resources/assets/js/app.js') }} --}}
</body>

View File

@ -0,0 +1,57 @@
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { readdirSync, statSync } from 'fs';
import { join,relative,dirname } from 'path';
import { fileURLToPath } from 'url';
export default defineConfig({
build: {
outDir: '../../public/build-$LOWER_NAME$',
emptyOutDir: true,
manifest: true,
},
plugins: [
laravel({
publicDirectory: '../../public',
buildDirectory: 'build-$LOWER_NAME$',
input: [
__dirname + '/resources/assets/sass/app.scss',
__dirname + '/resources/assets/js/app.js'
],
refresh: true,
}),
],
});
// Scen all resources for assets file. Return array
//function getFilePaths(dir) {
// const filePaths = [];
//
// function walkDirectory(currentPath) {
// const files = readdirSync(currentPath);
// for (const file of files) {
// const filePath = join(currentPath, file);
// const stats = statSync(filePath);
// if (stats.isFile() && !file.startsWith('.')) {
// const relativePath = 'Modules/$STUDLY_NAME$/'+relative(__dirname, filePath);
// filePaths.push(relativePath);
// } else if (stats.isDirectory()) {
// walkDirectory(filePath);
// }
// }
// }
//
// walkDirectory(dir);
// return filePaths;
//}
//const __filename = fileURLToPath(import.meta.url);
//const __dirname = dirname(__filename);
//const assetsDir = join(__dirname, 'resources/assets');
//export const paths = getFilePaths(assetsDir);
//export const paths = [
// 'Modules/$STUDLY_NAME$/resources/assets/sass/app.scss',
// 'Modules/$STUDLY_NAME$/resources/assets/js/app.js',
//];