PHP code example of boktoso-enterprise / laravel-model-doc
1. Go to this page and download the library: Download boktoso-enterprise/laravel-model-doc 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' );
boktoso-enterprise / laravel-model-doc example snippets
use Illuminate \Database \Eloquent \Model ;
use Illuminate \Database \Eloquent \Relations \HasMany ;
class MyModel extends Model
{
protected $table = 'models' ;
public function teams () : HasMany // 2. Add relation methods return types
{
return $this ->hasMany(Team::class);
}
public function getNameAttribute () : string // 3. Add accessor methods return types
{
return ucfirst($this ->name);
}
}
use Illuminate \Database \Eloquent \Builder ;
use Illuminate \Database \Eloquent \Factories \HasFactory ;
use Illuminate \Database \Eloquent \Model ;
class MyUser extends Model
{
use HasFactory ;
protected $table = 'users' ;
protected $casts = [
'children' => 'array' ,
];
public function teams () : HasMany
{
return $this ->hasMany(Team::class);
}
public function scopeWhereTeamName (Builder $builder, string $name)
{
$builder->where('name' , $name);
}
public function getPrettyTitleAttribute () : string
{
return ucfirst($this ->title);
}
protected static function newFactory ()
{
return new \Database\Factoies\MyUserFactory();
}
}
use Illuminate \Support \ServiceProvider ;
use BoktosoEnterprise \ModelDoc \Services \DocumentationGenerator ;
class AppServiceProvider extends ServiceProvider
{
public function register ()
{
DocumentationGenerator::usePath(fn () => base_path('app/Models' ));
}
}
'dbal' => [
'types' => [
'enum' => Doctrine\DBAL\Types\StringType::class,
],
],
php artisan vendor:publish --provider="boktoso-enterprise\ModelDoc\Providers\ModelDocServiceProvider"
php artisan model-doc:generate
php artisan model-doc:generate -v
php artisan model-doc:generate --model={modelClass}