PHP code example of clydescobidal / larasearch

1. Go to this page and download the library: Download clydescobidal/larasearch 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/ */

    

clydescobidal / larasearch example snippets



 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
use Clydescobidal\Larasearch\Searchable;
 
class Post extends Model
{
    use Searchable;
}



$post= Post::search('my post title')->get();
$posts = Post::search('search posts')->paginate();



$post= Post::find(1);
$post->searchable(); // Adds this model to the search index

$post= Post::find(2);
$post->unsearchable(); // Removes this model from the search index
bash
php artisan vendor:publish --provider="Clydescobidal\Larasearch\LarasearchServiceProvider"
bash
php artisan migrate
bash
php artisan make:searchable "App\Models\Post"
bash
php artisan make:unsearchable "App\Models\Post"
bash
php artisan cache:clear --tags="App\Models\Post"