2017 © Pedro Peláez
 

package eloquent-simple-searchable

An Eloquent Simple Searchable Scope.

image

vluzrmos/eloquent-simple-searchable

An Eloquent Simple Searchable Scope.

  • Monday, October 12, 2015
  • by vluzrmos
  • Repository
  • 1 Watchers
  • 1 Stars
  • 100 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Eloquent Simple Searchable

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Installation

composer require vluzrmos/eloquent-simple-searchable, (*2)

Usage

Put that trait into your model:, (*3)


namespace App; use Illuminate\Database\Eloquent\Model; use Vluzrmos\SimpleSearchable\Eloquent\SimpleSearchableTrait; class User extends Model { use SimpleSearchableTrait; protected $searchable = [ 'field' => 'type' ]; }

The attribute $searchable should contain the index with a column or a related column and the value is a type of the search which includes:, (*4)

  • left_text: Match the left side of the column value
  • right_text: Match the right side of the column value
  • equals: The searchd text should be equals to the column value
  • full_text: The searched text should be in any position of the searchd column.

Real Life Usage


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); } }

And in your controller or anywhere:, (*5)

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

// or replace the default searchable fields:

$users = User::search('Jonh', ['name' => 'full_text'])->get();

Note: The search method is a scope, so you need to use query builder methods like get or all to perform the search and get a collection of the results., (*6)

The Versions

12/10 2015

dev-master

9999999-dev

An Eloquent Simple Searchable Scope.

  Sources   Download

MIT

The Requires

 

database laravel eloquent

12/10 2015

v0.0.2

0.0.2.0

An Eloquent Simple Searchable Scope.

  Sources   Download

MIT

The Requires

 

database laravel eloquent

15/09 2015

v0.0.1

0.0.1.0

A Eloquent Simple Searchable Scope.

  Sources   Download

MIT

The Requires

 

database laravel eloquent