Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ssistemas committed Apr 6, 2017
1 parent 6fd72ab commit b94f9e6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# searchable
# Searchable for Laravel 5.*a simple trait to use with your Laravel Models## Usage### Step 1: Install Through Composer``` composer require ssistemas/searchable:"1.*"```### Step 2: Install Trait modeljust add in your models```php class User extends Model { use Ssistemas\Searchable\Traits\Searchable; private $searchable = ['name','nickname']; ... }```### Step 2: Use Controlleryou can also use controller```php $users = User::search($value)->get();```
Expand Down
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "ssistemas/searchable",
"description": "Laravel 5 searchable",
"keywords": ["laravel", "eloquent", "search", "searchable", "database", "model"],
"license": "MIT",
"authors": [
{
"name": "Santiago Lima Monteiro",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Ssistemas\\Searchable\\": "src/"
}
},

"minimum-stability": "dev",
"require": {
"php":">=5.6.4",
"illuminate/database": "~5.0"
}
}
28 changes: 28 additions & 0 deletions src/Traits/Searchable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Ssistemas\Searchable\Traits;

use \Illuminate\Database\Eloquent\Builder;

trait Searchable {

/**
* Apply filters in your QueryBuilder based in $fields
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $fields
*
*/
public function scopeSearch(Builder $query,$value)
{
if (isset($this->searchable))
{
foreach ($this->searchable as $key)
{
$query = $query->orWhere($key, 'LIKE', '%'.$value.'%');
}
return $query;
}
}

}

0 comments on commit b94f9e6

Please sign in to comment.