Put SearchTrait.php
in app
directory. Then use SearchTrait
in your model, like so
use App\SearchTrait;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use SearchTrait; // Add this
// Optional properties
protected $search = ['title', 'content'];
}
Somewhere in your controller
$keyword = 'lorem';
// Match any fields
Article::search($keyword)->paginate();
// Match all fields
Article::search($keyword, true)->paginate();
great. useful. more helpful than 30 minutes cbt clips
i think this is new great idea for developers... instead of hours of video in youtube. we can read it more rapid