PHP code example of jochemict / larasearch

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

    

jochemict / larasearch example snippets


use JochemICT\Larasearch\Larasearchable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Larasearchable;

    /**
     * The attributes that are searchable via Larasearch.
     *
     * @var array
     */
    protected $searchable = ['name', 'email', 'city'];
}

public function index(Request $request)
{
    $searchTerm = $request->input('search');

    $users = User::search($searchTerm)->get();

    return view('users.index', compact('users'));
}

$users = User::search($request->input('search'))->paginate(15);

$users = User::where('active', true)
             ->search($request->input('search'))
             ->get();

$users = User::search(null)->get(); // returns all users