PHP code example of meehh / laravel-goat

1. Go to this page and download the library: Download meehh/laravel-goat 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/ */

    

meehh / laravel-goat example snippets


Schema::create('products', function($t){
  $t->id();
  $t->foreignId('category_id')->constrained();
  $t->string('name');
  $t->decimal('price',10,2);
  $t->timestamps();
});

protected $fillable = ['category_id','name','price'];
protected function casts(): array { return ['price' => 'decimal:2']; }
public function category(){ return $this->belongsTo(Category::class,'category_id'); }

// config/goat.php
return [
  'paths' => [
    'model' => app_path('Models'),
    'migration' => database_path('migrations'),
    'request' => app_path('Http/Requests'),
    'resource' => app_path('Http/Resources'),
    'controller' => app_path('Http/Controllers'),
    'service' => app_path('Services'),
    'repository' => app_path('Repositories'),
    'policy' => app_path('Policies'),
    'test' => base_path('tests/Feature'),
  ],
  'namespaces' => ['model' => 'App\\Models', /* ... */],
  'generate' => ['model'=>true, /* ... */],
];
bash
php artisan goat:make Product

Product
โ”œโ”€โ”€ ๐Ÿ“„ 2024_*_create_products_table.php
โ”œโ”€โ”€ ๐Ÿงฉ Product.php (fillable, casts, belongsTo)
โ”œโ”€โ”€ โœ… StoreProductRequest.php
โ”œโ”€โ”€ โœ… UpdateProductRequest.php
โ”œโ”€โ”€ ๐Ÿ”Œ ProductResource.php
โ”œโ”€โ”€ ๐ŸŽฎ ProductController.php (thin)
โ”œโ”€โ”€ ๐Ÿง  ProductService.php (business)
โ”œโ”€โ”€ ๐Ÿ—„๏ธ ProductRepository.php (query)
โ”œโ”€โ”€ ๐Ÿ”’ ProductPolicy.php
โ””โ”€โ”€ ๐Ÿงช ProductTest.php
bash
cat migration.php | php artisan goat:make Product --from=migration --force
cat erd.txt | php artisan goat:make Product --from=erd --force
php artisan goat:make Product --from=database/migrations/2024_01_01_create_products_table.php
php artisan goat:make Product --only=model,resource,request
php artisan goat:make Product --except=policy,test
# custom paths — e.g. repo/admin instead of repositories/
php artisan goat:make Hello --paths=repository=app/Repo/Admin,model=app/Domain/Models --force
# → app/Repo/Admin/HelloRepository.php (App\Repo\Admin) + app/Domain/Models/Hello.php
php artisan goat:make World --module=Admin --force
# → app/Modules/Admin/Models/World.php + app/Modules/Admin/Repositories/...
# interactive: after schema preview GOAT asks “Customize output paths?” → type per component
bash
php artisan vendor:publish --tag=goat-stubs
# → resources/stubs/vendor/goat/*.stub — edit once, generate forever

src/
โ”œโ”€โ”€ Commands/MakeCommand.php          # UX, STDIN, --from/--only/--except/--force
โ”œโ”€โ”€ Parsers/MigrationParser.php       # Blueprint → GoatSchema
โ”‚        ErdParser.php                # ERD → GoatSchema (infer types)
โ”œโ”€โ”€ Schema/GoatSchema|Table|Column|Relationship  # ← single source
โ”œโ”€โ”€ Generators/* (9)                  # Model/Migration/Request/Resource/Controller/Service/Repository/Policy/Test
โ”œโ”€โ”€ Support/NameResolver|StubRenderer|FileWriter|GoatConfig
โ””โ”€โ”€ GoatServiceProvider.php           # config + publish + command