Im currently using the Spatie\MediaLibrary for my reviews model.
I got a query getting all reviews but im trying to show reviews that has images first using orderBy.
app\Models\Product.php Not working
public function reviews(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Review::class)->orderBy('media');
}
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'media' in 'order clause'
Using has 'media' or doesnthave 'media' works. But I would like in the 1 query.
public function activeImageReviews(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Review::class)->has('media');
If there exists a column called 'media' in the database you mig try: