PHP code example of amranibrahem / laravel-model-generator
1. Go to this page and download the library: Download amranibrahem/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/ */
amranibrahem / laravel-model-generator example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property int $id
* @property string $name
* @property string $email
* @property string $password
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property-read \App\Models\Comment[] $comments
* @property-read \App\Models\Post[] $posts
*/
class User extends Model
{
use HasFactory;
protected $table = 'users';
protected $fillable = [
'name',
'email',
'password'
];
protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime'
];
/**
* Get all the Comment for the User.
*/
public function comments()
{
return $this->hasMany(Comment::class, 'user_id', 'id');
}
/**
* Get all the Post for the User.
*/
public function posts()
{
return $this->hasMany(Post::class, 'user_id', 'id');
}
}
/**
* @property \App\Models\Tag[] $tags
*/
class Post extends Model
{
public function tags()
{
return $this->belongsToMany(Tag::class, 'post_tag', 'post_id', 'tag_id');
}
}