Created
March 10, 2023 14:55
-
-
Save tushargugnani/d20dd31860eb5dfb4450fb858809fd43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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