PHP code example of liveintent / laravel-resource-search
1. Go to this page and download the library: Download liveintent/laravel-resource-search library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
liveintent / laravel-resource-search example snippets
// find employees where `name` = "Michael"
GET /employees?filter[name]=Michael
// find employees where `name` like "Michael%"
GET /employees?filter[name]=Michael*
// find employees where `name` like "Michael%" OR `name` like "Dwight"
GET /employees?filter[name]=Michael*,Dwight
// find employees where `name` = "Michael" AND `email` like "%@dundermifflin.com"
GET /employees?filter[name]=Michael&filter[email]=*@dundermifflin.com
// find employees where `email` like "%@dundermifflin.com" order by `hired_at`
GET /employees?filter[email]=*@dundermifflin.com&sort=hired_at
// find employees where `email` like "%@dundermifflin.com" order by `hired_at` desc
GET /employees?filter[email]=*@dundermifflin.com&sort=-hired_at
// find the two most recently hired employees where any searchable field contains "stamford"
GET /employees?q=stamford&sort=-hired_at&page[size]=2
use Illuminate\Http\Resources\Json\JsonResource;
use LiveIntent\LaravelResourceSearch\Searchable;
use LiveIntent\LaravelResourceSearch\Contracts\SearchableResource;
class PostResource extends JsonResource implements SearchableResource
{
use Searchable;
/**
* The base model of the resource.
*/
public $model = \App\Models\Post::class;
}
use App\Http\Resources\PostResource;
Route::get('/posts', function () {
return PostResource::basicSearch();
});
use App\Models\Post;
use App\Http\Resources\PostResource;
Route::get('/published-posts', function () {
return PostResource::basicSearch(Post::published());
});
use App\Http\Resources\PostResource;
Route::post('/posts/search', function () {
return PostResource::search();
});
use App\Models\Post;
use App\Http\Resources\PostResource;
Route::post('/published-posts/search', function () {
return PostResource::search(Post::published());
});