PHP code example of arnaldo-tomo / laravel-autoscema

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

    

arnaldo-tomo / laravel-autoscema example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $fillable = ['name', 'email', 'age'];
    
    protected $casts = [
        'email_verified_at' => 'datetime',
        'preferences' => 'json',
    ];
    
    public function posts()
    {
        return $this->hasMany(Post::class);
    }
}



namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreateUserRequest extends FormRequest
{
    public function rules()
    {
        return [
            'name' => '



return [
    'output' => [
        'path' => resource_path('js/types'),
        'filename_case' => 'pascal', // pascal, camel, snake, kebab
        'export_format' => 'named', // named, default, namespace
    ],

    'models' => [
        'directories' => [
            app_path('Models'),
        ],
        '
];

class Product extends Model
{
    protected $casts = [
        'metadata' => 'json',
        'status' => ProductStatus::class, // Enum
    ];
    
    public function variants()
    {
        return $this->hasMany(ProductVariant::class);
    }
}

class Product extends Model
{
    protected $fillable = ['name', 'price', 'description'];
    
    protected $casts = [
        'price' => 'decimal:2',
        'metadata' => 'json',
        'status' => ProductStatus::class,
    ];
    
    public function category()
    {
        return $this->belongsTo(Category::class);
    }
    
    public function variants()
    {
        return $this->hasMany(ProductVariant::class);
    }
}
bash
php artisan schema:init
bash
# Generate for specific models
php artisan schema:generate --model=User --model=Post
bash
# Watch for changes and regenerate automatically
php artisan schema:watch

# Watch with custom interval
php artisan schema:watch --interval=5

# Watch in quiet mode
php artisan schema:watch --quiet
bash
php artisan vendor:publish --provider="ArnaldoTomo\LaravelAutoSchema\AutoSchemaServiceProvider" --tag="autoscema-config"
bash
php artisan schema:generate --dry-run