PHP code example of ozankurt / laravel-modules-core

1. Go to this page and download the library: Download ozankurt/laravel-modules-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ozankurt / laravel-modules-core example snippets


return [
    'user_model' => env('KURTMODULES_USER_MODEL'),
];

use Illuminate\Console\Command;
use Kurt\Modules\Core\Concerns\AbortsInProduction;

class SeedDemoCommand extends Command
{
    use AbortsInProduction;

    protected $signature = 'blog:demo {--force}';

    public function handle(): int
    {
        if ($this->abortIfProduction()) {
            return self::FAILURE;
        }

        // ... seed demo data ...

        return self::SUCCESS;
    }
}

use Filament\Support\Contracts\HasColor;
use Filament\Support\Contracts\HasLabel;
use Kurt\Modules\Core\Concerns\HasEnumLabels;

enum Status: string implements HasColor, HasLabel
{
    use HasEnumLabels;

    case Draft = 'draft';
    case InReview = 'in_review'; // getLabel() => "In Review"
    case Published = 'published';

    // Optional: override getColor() per case; getLabel() keeps the default.
    public function getColor(): string|array|null
    {
        return match ($this) {
            self::Published => 'success',
            default => null,
        };
    }
}

'http' => [
    'mode' => env('BLOG_HTTP_MODE', 'headless'),
    'prefix' => 'api/blog',
    'middleware' => ['api'],
    'auth_middleware' => ['auth:sanctum'],
    'rate_limit' => '60,1',
],

// Single: pass the resource itself — nested resources are not re-wrapped.
return $this->respond(PostResource::make($post));

// Collection: map through the resource, then envelope.
return $this->respondPaginated($paginator, PostResource::class);

   use Illuminate\Support\Facades\Route;

   // Read (public) endpoints — base middleware + throttle.
   Route::get('posts', [PostController::class, 'index'])->name('posts.index');
   Route::get('posts/{post}', [PostController::class, 'show'])->name('posts.show');

   // Write endpoints — add the module auth middleware.
   Route::group(['middleware' => config('blog.http.auth_middleware', ['auth'])], function () {
       Route::post('posts', [PostController::class, 'store'])->name('posts.store');
       Route::patch('posts/{post}', [PostController::class, 'update'])->name('posts.update');
       Route::delete('posts/{post}', [PostController::class, 'destroy'])->name('posts.destroy');
   });
   

   public function packageBooted(): void
   {
       parent::packageBooted();

       $this->registerModuleApi(__DIR__.'/../../routes/api.php');
   }
   
bash
php artisan vendor:publish --tag="kurtmodules-config"