PHP code example of mawuekom / laravel-searchable

1. Go to this page and download the library: Download mawuekom/laravel-searchable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mawuekom / laravel-searchable example snippets


'providers' => [
    ...
    Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class,
    ...
]

// Add provider 
$app->register(Mawuekom\LaravelSearchable\LaravelSearchableServiceProvider::class);



namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    ...

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title',
        'content'
    ];

     ...
}


use App\Models\Post;

Post::whereLike(['title', 'content'], 'Post title');




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mawuekom\LaravelSearchable\Searchable;

class Post extends Model
{
    use Searchable;

    ...
}


use App\Models\Post;

Post::search(['title', 'content'], 'Post title') ->get();