PHP code example of maheralyamany / laravel-model-generator
1. Go to this page and download the library: Download maheralyamany/laravel-model-generator 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/ */
maheralyamany / laravel-model-generator example snippets
public function register()
{
if ($this->app->environment() === 'local' && class_exists(\ModelGenerator\ModelGeneratorServiceProvider::class)) {
$this->app->register(\ModelGenerator\ModelGeneratorServiceProvider::class);
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property int $role_id
* @property mixed $username
* @property mixed $email
* @property Role $role
* @property Article[] $articles
* @property Comment[] $comments
*/
class User extends Model
{
/**
* @var array
*/
protected $fillable = ['role_id', 'username', 'email'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function role()
{
return $this->belongsTo('Role');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function articles()
{
return $this->hasMany('Article');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
{
return $this->hasMany('Comment');
}
}
class PerPageProcessor implements ProcessorInterface
{
public function process(EloquentModel $model, Config $config): void
{
$propertyModel = new PropertyModel('perPage', 'protected', 20);
$dockBlockModel = new DocBlockModel(
'The number of models to return for pagination.',
'',
'@var int'
);
$propertyModel->setDocBlock($dockBlockModel);
$model->addProperty($propertyModel);
}
public function getPriority(): int
{
return 8;
}
}
public function register()
{
$this->app->tag([InflectorRulesProcessor::class], [ModelGeneratorServiceProvider::PROCESSOR_TAG]);
}
/**
* The number of models to return for pagination.
*
* @var int
*/
protected $perPage = 20;