PHP code example of vluzrmos / eloquent-simple-searchable
1. Go to this page and download the library: Download vluzrmos/eloquent-simple-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/ */
vluzrmos / eloquent-simple-searchable example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
use Vluzrmos\SimpleSearchable\Eloquent\SimpleSearchableTrait;
class User extends Model
{
use SimpleSearchableTrait;
protected $searchable = [
'field' => 'type'
];
}
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Vluzrmos\SimpleSearchable\Eloquent\SimpleSearchableTrait;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, SimpleSearchableTrait;
protected $searchable = [
'name' => 'full_text',
'posts.title' => 'full_text',
// query deeply into your relations, that relations should exists on the respective models.
'posts.comments.owner.name' => 'full_text'
];
public function posts()
{
return $this->hasMany(Post::class);
}
}
$users = User::search('Jonh')->get();
// or replace the default searchable fields:
$users = User::search('Jonh', ['name' => 'full_text'])->get();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.