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