Indexing your Base-Model
Instant config. Add the Indexable trait to your Base Model then set your Index Model and you’re good to go.
1. Add the Indexable Trait to Your Base-Model
Section titled “1. Add the Indexable Trait to Your Base-Model” use PDPhilip\ElasticLens\Indexable;
class Profile extends Model{ use Indexable;2 (a) Create an Index-Model for your Base-Model
Section titled “2 (a) Create an Index-Model for your Base-Model”- ElasticLens expects the Index Model to be named as
Indexed+BaseModelNameand located in theApp\Models\Indexesdirectory.
namespace App\Models\Indexes;
use PDPhilip\ElasticLens\IndexModel;
class IndexedProfile extends IndexModel{}2 (b) Or create with artisan
Section titled “2 (b) Or create with artisan”php artisan lens:make ProfileGenerates a new index for the Profile model.

- That’s it! Your
Profilemodel will now automatically sync with theIndexedProfilemodel whenever changes occur. You can search your User model effortlessly, like:
Profile::viaIndex()->searchTerm('running')->orSearchTerm('swimming')->get();Build Indexes for existing data
Section titled “Build Indexes for existing data”php artisan lens:build ProfileBuild/Rebuilds all the IndexedProfile records for the Profile model.
