PHPackages                             tonymans33/laravel-searchable-with-recent-search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. tonymans33/laravel-searchable-with-recent-search

ActiveLibrary[Search &amp; Filtering](/categories/search)

tonymans33/laravel-searchable-with-recent-search
================================================

Pragmatically search through models and other sources, with a recent search feature. build on top of Spatie Searchable.

v1.0.7(1y ago)1146MITPHPPHP ^7.3|^8.0

Since Jan 22Pushed 1y agoCompare

[ Source](https://github.com/tonymans33/laravel-searchable-with-recent-search)[ Packagist](https://packagist.org/packages/tonymans33/laravel-searchable-with-recent-search)[ Docs](https://github.com/tonymans33/laravel-searchable-with-recent-search)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/tonymans33-laravel-searchable-with-recent-search/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (8)Used By (0)

Laravel Searchable with Recent Search Feature
=============================================

[](#laravel-searchable-with-recent-search-feature)

[![Latest Version on Packagist](https://camo.githubusercontent.com/50a957fab28366b21e5087ea0b78d9091a3b67cc0c6e77faf9c4783ed54bcc3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d73656172636861626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-searchable)[![run-tests](https://github.com/spatie/laravel-searchable/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-searchable/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/bd36d142aa10630b99f2ab8e690f6d7fd604f08cf2907f714a45d185a41a72be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d73656172636861626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-searchable)

This package makes it easy to get structured search from a variety of sources. Here's an example where we search through some models. We already did some small preparation on the models themselves.

```
$searchResults = (new Search())
   ->registerModel(User::class, 'name')
   ->registerModel(BlogPost::class, 'title')
   ->search('john');
```

The search will be performed case insensitive. `$searchResults` now contains all `User` models that contain `john` in the `name` attribute and `BlogPost`s that contain 'john' in the `title` attribute.

In your view you can now loop over the search results:

```
Search

There are {{ $searchResults->count() }} results.

@foreach($searchResults->groupByType() as $type => $modelSearchResults)
   {{ $type }}

   @foreach($modelSearchResults as $searchResult)

            {{ $searchResult->title }}

   @endforeach
@endforeach
```

In this example we used models, but you can easily add a search aspect for an external API, list of files or an array of values.

---

Recent Search Feature
---------------------

[](#recent-search-feature)

### About

[](#about)

This package now includes a recent search feature that allows tracking, retrieving, and managing user searches efficiently.

### Installation

[](#installation)

1. **Install Package Cia Composer**

    Run the following command to install the package

    ```
    composer require tonymans33/laravel-searchable-with-recent-search
    ```
2. **Publish Config and Migration Files**

    Run the following command to publish the configuration and migration files:

    ```
    php artisan vendor:publish --provider="Tonymans33\SearchableWithRecent\Providers\RecentSearchServiceProvider"
    ```
3. **Run Migrations**

    After publishing the migration files, migrate your database:

    ```
    php artisan migrate
    ```
4. **Update the Config File**

    In the `config/recentsearch.php` file, set the `user_model` to your User model:

    ```
    'user_model' => App\Models\User::class,
    ```

### Usage

[](#usage)

#### Add the Trait

[](#add-the-trait)

To enable recent search functionality for a model, add the `HasRecentSearchTrait` to it:

```
use HasRecentSearchTrait;
```

#### Available Functions

[](#available-functions)

- **Store a Recent Search**

    ```
    User::storeRecentSearch($request->q);
    ```

    This saves the recent search query for the user.
- **Retrieve Recent Searches**

    ```
    $recentSearches = User::getRecentSearches();
    ```

    This retrieves all recent searches for the user.
- **Delete a Specific Search Record**

    ```
    User::deleteRecentSearchRecord($id);
    ```

    This deletes a specific search record by its ID.
- **Clear All Recent Searches**

    ```
    User::clearRecentSearches();
    ```

    This clears all recent search records for the user.

---

Original Features
-----------------

[](#original-features)

### Preparing your models

[](#preparing-your-models)

In order to search through models you'll have to let them implement the `Searchable` interface.

```
namespace Tonymans33\SearchableWithRecent;

interface Searchable
{
    public function getSearchResult(): SearchResult;
}
```

You'll only need to add a `getSearchResult` method to each searchable model that must return an instance of `SearchResult`. Here's how it could look like for a blog post model.

```
use Tonymans33\SearchableWithRecent\Searchable;
use Tonymans33\SearchableWithRecent\SearchResult;

class BlogPost extends Model implements Searchable
{
     public function getSearchResult(): SearchResult
     {
        $url = route('blogPost.show', $this->slug);

         return new \Tonymans33\SearchableWithRecent\SearchResult(
            $this,
            $this->title,
            $url
         );
     }
}
```

---

Credits
-------

[](#credits)

- [Alex Vanderbist](https://github.com/AlexVanderbist)
- [Freek Van der Herten](https://github.com/freekmurze)
- [Tony Mansour](https://github.com/tonymans33) ()
- [All Contributors](../../contributors)

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance42

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

7

Last Release

469d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/36414b284c92e487e3413045f1c121b692befbb764f0224eced7cc37e9b7139a?d=identicon)[tony.mans33](/maintainers/tony.mans33)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (90 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (38 commits)")[![tonymans33](https://avatars.githubusercontent.com/u/66672357?v=4)](https://github.com/tonymans33 "tonymans33 (10 commits)")[![jadsalhani](https://avatars.githubusercontent.com/u/6623311?v=4)](https://github.com/jadsalhani "jadsalhani (8 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (7 commits)")[![netpok](https://avatars.githubusercontent.com/u/6945600?v=4)](https://github.com/netpok "netpok (6 commits)")[![larsjanssen6](https://avatars.githubusercontent.com/u/7254997?v=4)](https://github.com/larsjanssen6 "larsjanssen6 (4 commits)")[![WalrusSoup](https://avatars.githubusercontent.com/u/5719851?v=4)](https://github.com/WalrusSoup "WalrusSoup (4 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![JamesFreeman](https://avatars.githubusercontent.com/u/916500?v=4)](https://github.com/JamesFreeman "JamesFreeman (3 commits)")[![SamuelNitsche](https://avatars.githubusercontent.com/u/24483576?v=4)](https://github.com/SamuelNitsche "SamuelNitsche (2 commits)")[![voydz](https://avatars.githubusercontent.com/u/373533?v=4)](https://github.com/voydz "voydz (2 commits)")[![mojtabaahn](https://avatars.githubusercontent.com/u/9845317?v=4)](https://github.com/mojtabaahn "mojtabaahn (2 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (1 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (1 commits)")[![PovilasKorop](https://avatars.githubusercontent.com/u/1510147?v=4)](https://github.com/PovilasKorop "PovilasKorop (1 commits)")[![grantholle](https://avatars.githubusercontent.com/u/1189456?v=4)](https://github.com/grantholle "grantholle (1 commits)")[![shuvroroy](https://avatars.githubusercontent.com/u/21066418?v=4)](https://github.com/shuvroroy "shuvroroy (1 commits)")[![SocolaDaiCa](https://avatars.githubusercontent.com/u/18243451?v=4)](https://github.com/SocolaDaiCa "SocolaDaiCa (1 commits)")

---

Tags

laravel-searchable-with-recent-search

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tonymans33-laravel-searchable-with-recent-search/health.svg)

```
[![Health](https://phpackages.com/badges/tonymans33-laravel-searchable-with-recent-search/health.svg)](https://phpackages.com/packages/tonymans33-laravel-searchable-with-recent-search)
```

###  Alternatives

[mehradsadeghi/laravel-filter-querystring

Filter your queries based on url query string parameters like a breeze.

169118.2k](/packages/mehradsadeghi-laravel-filter-querystring)[pos-lifestyle/laravel-nova-date-range-filter

A Laravel Nova date range filter.

16179.1k](/packages/pos-lifestyle-laravel-nova-date-range-filter)[omure/scout-advanced-meilisearch

Laravel Scout extension that allows to use meilisearch advanced features as well as has an extended collection driver for testing purposes.

123.9k](/packages/omure-scout-advanced-meilisearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
