Skip to content

Instantly share code, notes, and snippets.

@tushargugnani
Created March 10, 2023 14:55
Show Gist options
  • Save tushargugnani/d20dd31860eb5dfb4450fb858809fd43 to your computer and use it in GitHub Desktop.
Save tushargugnani/d20dd31860eb5dfb4450fb858809fd43 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use EloquentFilter\Filterable;
use Spatie\MediaLibrary\HasMedia;
use Spatie\Searchable\Searchable;
use Spatie\Searchable\SearchResult;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Spatie\MediaLibrary\InteractsWithMedia;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class DummyProduct extends Model implements HasMedia, Searchable
{
use HasFactory;
use InteractsWithMedia;
use Filterable;
// Model
protected $casts = [
'meta' => 'collection',
];
public function registerMediaCollections(): void
{
$this->addMediaCollection('main')->singleFile();
}
public function getSearchResult(): SearchResult
{
return new SearchResult(
$this,
$this->title,
$this->link
);
}
public function scopeFilterPrice(Builder $query, $operator, $price)
{
return $query->where('price', $operator, $price);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment