<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Article extends Model
{
// 略
public function getCountLikesAttribute(): int
{
return $this->likes->count();
}
//===========ここから追加===========
public function tags(): BelongsToMany
{
return $this->belongsToMany('App\Tag')->withTimestamps();
}
//===========ここまで追加===========
}