### Running Laravel Migration PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_add_migration_file_content__1.txt Defines the `up` method, which is executed when the migration is run. This method should contain the logic to create or modify database tables and columns. In this example, it shows an empty closure for the `posts` table, indicating no schema changes are currently defined. ```PHP /** * Run the migrations. */ public function up(): void { Schema::table('posts', function (Blueprint $table) { }); } ``` -------------------------------- ### Basic Unit Test Class Setup PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_unit_namespace__1.txt This snippet provides the complete code for a minimal unit test class in a Laravel module. It extends the base `TestCase` class, which provides Laravel testing helpers, and includes a basic test method demonstrating how to write and run a test. ```PHP assertTrue(true); } } ``` -------------------------------- ### Installing Project Dependencies (composer) - bash Source: https://github.com/nwidart/laravel-modules/blob/master/CONTRIBUTING.md Installs the necessary development dependencies for the project using Composer. This command should be run after cloning the repository to set up the development environment and get started with contributions. ```bash composer install ``` -------------------------------- ### Booting Module Components Laravel Service Provider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This method is called after all service providers have been registered. It's used to boot various module components such as commands, schedules, translations, configurations, views, and migrations. ```php /** * Boot the application events. */ public function boot(): void { $this->registerCommands(); $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } ``` -------------------------------- ### Installing Laravel-Modules via Composer (Bash) Source: https://github.com/nwidart/laravel-modules/blob/master/README.md This command uses Composer to require and install the nwidart/laravel-modules package into your Laravel project. This is the first step to integrating modular capabilities. ```bash composer require nwidart/laravel-modules ``` -------------------------------- ### Defining Provided Services Laravel Service Provider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This method lists the services provided by this service provider. While currently empty, it could be used to defer loading the provider until one of the listed services is needed. ```php /** * Get the services provided by the provider. */ public function provides(): array { return []; } ``` -------------------------------- ### Defining Laravel Module Resource Controller in PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generated_correct_file_with_content__1.txt This snippet defines a standard Laravel resource controller for a module named 'Blog'. It includes placeholder methods for common resource operations (index, create, store, show, edit, update, destroy) and demonstrates returning views specific to the module (e.g., 'blog::index'). It requires the `Illuminate\Http\Request` class for methods handling requests. ```PHP commands()` method. ```php /** * Register commands in the format of Command::class */ protected function registerCommands(): void { // $this->commands([]); } ``` -------------------------------- ### Getting Publishable View Paths Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt This helper method scans the application's configured view paths to find directories specific to this module. It is used by `registerViews` to load views from locations where they might have been published. ```PHP 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; } ``` -------------------------------- ### Defining a Laravel Module Service Provider - PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt This snippet defines the `MyBlogServiceProvider` class, extending Laravel's base `ServiceProvider`. It includes the standard `register` method for binding services and the `provides` method to declare provided services, though both are currently empty, acting as a starting point for module service configuration. ```PHP app->booted(function () { // $schedule = $this->app->make(Schedule::class); // $schedule->command('inspire')->hourly(); // }); } ``` -------------------------------- ### Defining Basic PHP Service Class Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ServiceMakeCommandTest__test_it_can_generate_a_service_in_sub_namespace_with_correct_generated_file__1.txt Defines a simple PHP class named `MyService` within the `Modules\Blog\Services\Api` namespace. This class contains a single public method `handle` which currently performs no action but serves as a placeholder for implementing specific service logic. ```php 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); } } } } ``` -------------------------------- ### Defining a Resource Controller in Laravel Module (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_api_controller__1.txt This PHP snippet defines a basic Laravel resource controller class, 'MyController', intended for use within a module structure. It extends the base Laravel Controller and provides empty implementations for the standard RESTful resource methods: index, store, show, update, and destroy. Each method accepts necessary parameters (like Request and ID) and currently returns an empty JSON response. ```php 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([]); } } ``` -------------------------------- ### Defining Laravel Module API Repository Class (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/RepositoryMakeCommandTest__test_it_can_generate_a_repository_in_sub_namespace_with_correct_generated_file__1.txt This PHP snippet defines a simple class `MyRepository` within the `Modules\Blog\Repositories\Api` namespace. It includes a basic, empty public method `handle()`, likely intended as a placeholder or a starting point for repository logic within a Laravel module's API layer. It requires a standard PHP environment compatible with namespaces and class definitions. ```php nameLower)) { $paths[] = $path.'/modules/'.$this->nameLower; } } return $paths; } ``` -------------------------------- ### Defining WelcomeChannel Class in PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ChannelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This snippet defines the `WelcomeChannel` class. It includes an empty constructor `__construct` and a `join` method. The `join` method is intended to authenticate a user's access to the channel, taking an `Operator` object as input and returning a boolean or an array. ```php call([]); } } ``` -------------------------------- ### Implementing Eloquent Custom Cast Class - Laravel - PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/CastMakeCommandTest__test_it_can_generate_a_cast_in_sub_namespace_with_correct_generated_file__1.txt This PHP class `MyCast` demonstrates how to create a custom cast for Laravel Eloquent models by implementing the `CastsAttributes` interface. It includes the required `get` method for casting attribute values from the database/model and the `set` method for preparing values before saving to the database. In this example, both methods simply return the input value without modification. ```PHP registerCommands(); $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } ``` -------------------------------- ### Reversing Laravel Migration PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_add_migration_file_content__1.txt Defines the `down` method, which is executed when the migration is rolled back. This method should contain the logic to reverse the changes made in the `up` method, typically by dropping tables or columns. In this example, it shows an empty closure for the `posts` table, indicating no rollback changes are currently defined. ```PHP /** * Reverse the migrations. */ public function down(): void { Schema::table('posts', function (Blueprint $table) { }); } ``` -------------------------------- ### Bootstrapping Laravel Module Service Provider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt The `boot` method is called after all service providers are registered. It orchestrates the loading of module resources by calling various registration methods and specifically loads database migrations. ```php /** * Boot the application events. */ public function boot(): void { $this->registerCommands(); $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } ``` -------------------------------- ### Registering Laravel Module Command Schedules PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt A protected method intended for defining scheduled Artisan commands for the module. It shows a commented-out example of accessing the schedule instance and adding a command schedule. ```php /** * Register command Schedules. */ protected function registerCommandSchedules(): void { // $this->app->booted(function () { // $schedule = $this->app->make(Schedule::class); // $schedule->command('inspire')->hourly(); // }); } ``` -------------------------------- ### Showing Create Blog Form View (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt This method handles requests to display the form for creating a new blog entry. It returns the view named 'blog::create', which should contain the form fields necessary to input new blog data. ```php return view('blog::create'); ``` -------------------------------- ### Registering Module Command Schedules PHP Laravel Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt This method is intended to register scheduled Artisan commands for the module. The current implementation is commented out, showing an example of how to access the scheduler and define scheduled tasks. ```PHP /** * Register command Schedules. */ protected function registerCommandSchedules(): void { // $this->app->booted(function () { // $schedule = $this->app->make(Schedule::class); // $schedule->command('inspire')->hourly(); // }); } ``` -------------------------------- ### Storing New Blog Resource Stub (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt Implements the `store` method, intended to handle the storage of a newly created blog resource. It accepts an `Illuminate\Http\Request` object containing input data but is currently an empty stub with no implementation logic. ```PHP /** * Store a newly created resource in storage. */ public function store(Request $request) {} ``` -------------------------------- ### Registering Module Commands PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt This method is intended for registering module-specific Artisan commands. The example shows how to use the `$this->commands()` method, although it is currently commented out, indicating no commands are registered by default. ```php /** * Register commands in the format of Command::class */ protected function registerCommands(): void { // $this->commands([]); } ``` -------------------------------- ### Booting Module Components PHP Laravel Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt The `boot` method is called after all service providers are registered. It performs actions needed during the application's booting process, such as registering commands, schedules, translations, configurations, views, and loading database migrations for the module. ```PHP /** * Boot the application events. */ public function boot(): void { $this->registerCommands(); $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } ``` -------------------------------- ### Displaying a Specific Resource in Laravel Controller PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model_using_shortcut_option__1.txt The `show` method retrieves and displays details for a single blog post resource, identified by its `$id`. It returns the `blog::show` view, which is responsible for rendering the specific post's content. ```PHP /** * Show the specified resource. */ public function show($id) { return view('blog::show'); } ``` -------------------------------- ### Showing Create Form for Blog Resource - Laravel PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt Shows the form for creating a new Blog resource. This method is responsible for preparing any data needed for the form (e.g., categories) and returning the view that contains the creation form. It returns the `blog::create` view. ```PHP public function create() { return view('blog::create'); } ``` -------------------------------- ### Defining Blog Database Seeder - PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__3.txt This snippet defines the main database seeder class for the Blog module. It extends `Illuminate\Database\Seeder` and includes a `run` method where calls to other seeders or direct database manipulations for seeding purposes would typically reside. ```php call([]); } } ``` -------------------------------- ### Getting Published View Paths PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt This private helper method searches the application's configured view paths for a directory corresponding to the module's published views. It is used by `registerViews` to prioritize published views over source views. ```php 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; } ``` -------------------------------- ### Basic Unit Test Class PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_unit_file_with_content__1.txt Defines a PHPUnit test class `EloquentPostRepositoryTest` that extends Laravel's `TestCase`. It includes a simple test method `test_that_true_is_true` which uses the `assertTrue` assertion, serving as a minimal example of a test structure within this context. ```php assertTrue(true); } } ``` -------------------------------- ### Implementing Blog Module RouteServiceProvider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This PHP class, extending Laravel's RouteServiceProvider, sets up the routing for the 'Blog' module. It defines methods to map web and API routes, loading them from 'routes/web.php' and 'routes/api.php' respectively within the module's directory, applying appropriate middleware ('web', 'api') and prefixes ('api') and naming ('api.'). It relies on the base RouteServiceProvider and the Facades for Route and Illuminate\Support. ```php 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, '/routes/web.php')); } /** * * 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, '/routes/api.php')); } } ``` -------------------------------- ### Handling Request in Invokable Controller (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt This method is automatically called when the controller is invoked as a single action. It receives the incoming `Request` object and returns an empty JSON response using Laravel's `response()->json([])`. It requires the `Illuminate\Http\Request` dependency. ```PHP json([]); } } ``` -------------------------------- ### Defining a Laravel View Component Class in PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ComponentClassMakeCommandTest__test_it_generated_correct_file_with_content__1.txt This PHP snippet defines the `Blog` class, which extends Laravel's `Component`. The constructor is empty, indicating no specific initialization parameters are needed. The `render` method specifies the view ('blog::components.blog') to be rendered when this component is used in a Blade template, effectively displaying the blog component's content. ```php nameLower)) { $paths[] = $path.'/modules/'.$this->nameLower; } } return $paths; } ``` -------------------------------- ### Merging Module Configuration Laravel Service Provider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This protected helper method merges configuration values from a module file into the application's existing configuration array under a specific key. It uses `array_replace_recursive` to handle nested configuration values gracefully. ```php /** * 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)]); } ``` -------------------------------- ### Defining Module Service Provider Class - PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt This code defines the BlogServiceProvider class, extending Laravel's ServiceProvider and utilizing the PathNamespace trait from the nwidart/laravel-modules package. It sets up methods for booting and registering module components such as commands, translations, configuration, views, and migrations within the Laravel application lifecycle. This class is the central point for integrating the module's services and resources. ```php registerCommands(); $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** * 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, 'lang'), $this->nameLower); $this->loadJsonTranslationsFrom(module_path($this->name, '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, 'resources/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; } } ``` -------------------------------- ### Defining Event Listener Class - PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ListenerMakeCommandTest__test_it_generated_correct_sync_duck_event_with_content__1.txt This snippet defines the `NotifyUsersOfANewPost` class, intended to function as a queued event listener in a Laravel module. It includes traits for queue interaction and an empty constructor and handle method as a starting point for custom event handling logic. ```php nameLower); $sourcePath = module_path($this->name, 'resources/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); } ``` -------------------------------- ### Displaying Blog Index View (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt Implements the `index` method for the resource controller. Its purpose is to display a listing of blog resources by returning the view located at `resources/views/index.blade.php` within the `blog` module's view namespace. ```PHP /** * Display a listing of the resource. */ public function index() { return view('blog::index'); } ``` -------------------------------- ### Registering Module Translations Laravel Service Provider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This method loads module translation files. It checks if language files exist in the standard application `resource_path`, otherwise, it loads them from the module's own `lang` directory, supporting both standard and JSON translation formats. ```php /** * 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, 'lang'), $this->nameLower); $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } ``` -------------------------------- ### Displaying Single Blog View (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt Implements the `show` method for displaying a specific blog resource. It accepts the resource ID as a parameter and returns the view located at `resources/views/show.blade.php` within the `blog` module's view namespace. ```PHP /** * Show the specified resource. */ public function show($id) { return view('blog::show'); } ``` -------------------------------- ### Registering Dependent Service Providers Laravel Service Provider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt This method is called when the service provider is being registered. It's typically used to bind things into the service container. In this case, it registers other service providers specific to the module, like event and route providers. ```php /** * Register the service provider. */ public function register(): void { $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } ``` -------------------------------- ### Defining Blog Database Seeder Class PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt This snippet defines the main database seeder class for the Blog module. It extends the base Laravel Seeder class and contains the 'run' method where all module-specific seeding logic should be implemented by calling other seeder classes or inserting data directly. ```php call([]); } } ``` -------------------------------- ### Testing Application Root Route Response (PHP) Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_feature_namespace__1.txt This test method verifies that accessing the root URL ('/') of the application results in a successful HTTP response, specifically a status code of 200. It utilizes Laravel's built-in testing helpers available through the TestCase class. ```PHP /** * A basic test example. */ public function test_the_application_returns_a_successful_response(): void { $response = $this->get('/'); $response->assertStatus(200); } ``` -------------------------------- ### Implementing Blog Post Resource Controller in Laravel PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_and_migration_when_both_flags_are_present__1.txt This PHP class defines a standard resource controller for managing blog posts within a Laravel application, designed for use with the nwidart/laravel-modules package. It provides implementations for standard resource methods (index, create, show, edit, store, update, destroy), focusing on returning module-specific views in this initial stub. ```php registerCommands(); $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } ``` -------------------------------- ### Getting Publishable View Paths PHP Laravel Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt A private helper method that checks the main application's configured view paths for published module view directories. It returns an array of paths where the module's views might be located outside the module's own directory, prioritizing published views. ```PHP 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; } ``` -------------------------------- ### Configuring Module Routes using RouteServiceProvider PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt This PHP class extends Laravel's RouteServiceProvider to define how routes for the 'Blog' module are registered. It uses the `map` method to delegate loading to `mapWebRoutes` and `mapApiRoutes`, which apply middleware and prefix configurations before including the module's `web.php` and `api.php` route files. ```php 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, '/routes/web.php')); } /** * 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, '/routes/api.php')); } } ``` -------------------------------- ### Defining a Basic Mail Notification Class in PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt This PHP class `WelcomeNotification` extends the base `Notification` class and uses the `Queueable` trait. It implements the `via` method to specify 'mail' as the delivery channel and the `toMail` method to build the email message using the `MailMessage` helper. It also includes a placeholder `toArray` method. ```php 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 []; } } ``` -------------------------------- ### Testing Basic Application Response Laravel PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_feature_namespace_specific__1.txt This PHP snippet defines a PHPUnit test case extending Laravel's `TestCase`. It includes a single test method `test_the_application_returns_a_successful_response` which sends an HTTP GET request to the '/' route and asserts that the response has a 200 status code, verifying basic application connectivity and health. ```php get('/'); $response->assertStatus(200); } } ``` -------------------------------- ### Defining Blog REST Controller Class in PHP Source: https://github.com/nwidart/laravel-modules/blob/master/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt Defines the `BlogController` class, extending `App\Http\Controllers\Controller`, for handling RESTful operations within the Blog module. It includes placeholder methods for standard resource actions (`index`, `store`, `show`, `update`, `destroy`), currently returning empty JSON responses. ```php 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([]); } } ```