Upload beautify
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
|
||||
use App\Models\Artwork;
|
||||
|
||||
class ContentType extends Model
|
||||
{
|
||||
@@ -19,6 +22,18 @@ class ContentType extends Model
|
||||
return $this->categories()->whereNull('parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Eloquent builder for Artworks that belong to this content type.
|
||||
* This traverses the pivot `artwork_category` via the `categories` relation.
|
||||
* Note: not a direct Eloquent relation (uses whereHas) so it can be queried/eager-loaded manually.
|
||||
*/
|
||||
public function artworks(): EloquentBuilder
|
||||
{
|
||||
return Artwork::whereHas('categories', function ($q) {
|
||||
$q->where('content_type_id', $this->id);
|
||||
});
|
||||
}
|
||||
|
||||
public function getRouteKeyName(): string
|
||||
{
|
||||
return 'slug';
|
||||
|
||||
Reference in New Issue
Block a user