Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Nov 15, 2024
1 parent 82a2f00 commit 41e224f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions workbench/app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@

class Comment extends Model
{
/** {@inheritDoc} */
protected $table = 'comments';

/** {@inheritDoc} */
#[\Override]
public static function boot()
{
parent::boot();

static::booted();
}

/** {@inheritDoc} */
#[\Override]
public static function booted()
{
static::addGlobalScope('id', function (Builder $builder) {
Expand Down
6 changes: 3 additions & 3 deletions workbench/app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Workbench\App\Models;

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

class Role extends Model
{
/** {@inheritDoc} */
protected $table = 'roles';

/**
* Has many and belongs to relationship with Role.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function users()
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'user_role', 'role_id', 'user_id')->withTimestamps();
}
Expand Down
11 changes: 5 additions & 6 deletions workbench/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
namespace Workbench\App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Model
{
use SoftDeletes;

/** {@inheritDoc} */
protected $table = 'users';

/**
* Has many to relationship with Post.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function posts()
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}

/**
* Has many and belongs to relationship with Role.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles()
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'user_role', 'user_id', 'role_id')->withTimestamps();
}
Expand Down

0 comments on commit 41e224f

Please sign in to comment.