Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abdulrahmanmasoud/laravel-search
Laravel search is package you can use it to make search query easy.
https://github.com/abdulrahmanmasoud/laravel-search
composer-package laravel laravel-framework laravel-package package php searching
Last synced: about 1 month ago
JSON representation
Laravel search is package you can use it to make search query easy.
- Host: GitHub
- URL: https://github.com/abdulrahmanmasoud/laravel-search
- Owner: AbdulrahmanMasoud
- Created: 2022-08-24T11:30:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-31T09:57:39.000Z (about 2 years ago)
- Last Synced: 2024-10-13T02:22:00.012Z (about 1 month ago)
- Topics: composer-package, laravel, laravel-framework, laravel-package, package, php, searching
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 6
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Laravel Search
## Installation
First, install the package through Composer.
```js
composer require theamasoud/laravel-search
```
or add this in your project's composer.json file .
````json
"require": {
"theamasoud/laravel-search": "1.*",
}
````-----
## Usage
### Traits
#### `TheAMasoud\LaravelSearch\Searchable`
Add the Searchable trait to your model:
```php
namespace App\Models;use Illuminate\Database\Eloquent\Model;
use TheAMasoud\LaravelSearch\Searchable;class Message extends Model
{
use Searchable;
protected $fillable = ['name','email','subject','message'];
}
```### Normal Search
first how to make a normel search or fillter, you should use ``search()`` method.
and you should pass a two parameters `column you need to search or fillter in` and `the request key thet come from your request`
#### Request key:#### Normal Search Example:
```php
$messages = Message::search('name','search')->get();
```
* In this example I am trying to search or filter in `name` column in messages table and the data I will search about it's come from request key `search` like:`($request->search)`
### Search Multiple
By multiple search you can search in multiple columns and multiple values from request.
how to make a multiple search or fillter, you should use ``searchMultiple()`` method.
and you should pass a one array parameter `column you need to search or fillter in array key` and `the request key thet come from your request as a value of key` like:`['name'=>'search_name','bio'=>'search_bio']`
#### Request keys:#### Search Multiple Example:
```php
$messages = Message::searchMultiple(['title'=>'search_title','description'=>'search_desc'])->get();
```
* In this example I am trying to search or filter in `title` column in messages table and the data I will search about it's come from request key `search_title` like:`($request->search)` etc... with `description`
### Search In Multiple Columns
By search in multiple you can search in multiple columns and one value from request.
how to make a search in multiple or fillter, you should use ``searchInMultiple()`` method.
and you should pass a two parameters `columns you need to search or fillter in` and `the request key thet come from your request as a value of key`
#### Request keys:#### Search In Multiple Example:
```php
$messages = Message::searchInMultiple(['title','description','etc...'],'search')->get();
```
* In this example I am trying to search or filter in `title` and `description` column in messages table and the data I will search about it's come from request key `search` like:`($request->search)`
### Search In Json Column
By search in json you can search in json column and value from request.
how to make a search in multiple or fillter, you should use ``jsonSearch()`` method.
and you should pass a two parameters `column you need to search or fillter in` and `the request key thet come from your request as a value of key`
#### Request keys:#### Search In Json Example:
##### My json colums has:
```json
{
"ar":"نص عربي",
"en":"English text"
}
```
```php
$messages = Message::jsonSearch('title->ar','search')->get();
```
* In this example I am trying to search or filter in `title` column in messages table and the data I will search about it's come from request key `search` like:`($request->search)`