2017 © Pedro Peláez
 

library searchable

a simple php trait for laravel to search in models and related models

image

beaumind/searchable

a simple php trait for laravel to search in models and related models

  • Wednesday, January 4, 2017
  • by beaumind
  • Repository
  • 1 Watchers
  • 3 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

searchable

a simple php trait for laravel >= 5.0 to search in models and related models, (*1)

Installation

Simply Run the Composer require comand., (*2)

composer require beaumind/searchable

Usage

Add the trait to your model and your search rules., (*3)

use Beaumind\Searchable\Searchable;

class Post extends \Eloquent
{
    use Searchable;

    /**
     * Searchable columns.
     *
     * @var array
     */
    public $searchable_fields = [
      title,
      body,
      user.name,
      uesr.email
    ];


    public function user()
    {
        return $this->belongsTo('User');
    }

}

Now you can search your model., (*4)

// Simple search
$posts = Post::search($query)->get();

// Search and get relations
// It will not get the relations if you don't do this
$posts = Post::search($query)
            ->with('user')
            ->get();

Search Paginated

As easy as laravel default queries, (*5)

// Search with relations and paginate
$posts = Post::search($query)
            ->with('user')
            ->paginate(20);

Mix queries

Search method is compatible with any eloquent method. You can do things like this:, (*6)

// Search only active posts
$posts = Post::where('status', 'active')
            ->search($query)
            ->paginate(20);

The Versions

04/01 2017

dev-master

9999999-dev

a simple php trait for laravel to search in models and related models

  Sources   Download

MIT

The Requires

 

by A.Hassani

04/01 2017

1.0.1

1.0.1.0

a simple php trait for laravel to search in models and related models

  Sources   Download

MIT

The Requires

 

by A.Hassani

04/01 2017

1.0.0

1.0.0.0

a simple php trait for laravel to search in models and related models

  Sources   Download

MIT

The Requires

 

by A.Hassani