PHP code example of axn / laravel-models-organizer

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

    

axn / laravel-models-organizer example snippets


use Axn\Multilingual\Models\Language as BaseModel;

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Article extends Model
{
    public function rubrique(): BelongsTo
    {
        return $this->belongsTo(Rubrique::class);
    }
}

namespace App\Models;

use App\Models\Concerns\Article\Relations;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    use Relations;
}

namespace App\Models\Concerns\Article;

use App\Models\Rubrique;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

trait Relations
{
    public function rubrique(): BelongsTo
    {
        return $this->belongsTo(Rubrique::class);
    }
}
bash
php artisan models:organize
bash
php artisan models:organize "App\Models\Article"
bash
php artisan models:organize --dry-run
txt
app/
└── Models/
    ├── Article.php
    └── Concerns/
        └── Article/
            ├── Relations.php
            ├── Scopes.php
            └── Attributes.php
txt
app/
└── Models/
    ├── Catalogue/
    │   └── Article.php
    └── Concerns/
        └── Catalogue/
            └── Article/
                ├── Relations.php
                ├── Scopes.php
                └── Attributes.php