1. Go to this page and download the library: Download abhiaay/query-craft 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/ */
abhiaay / query-craft example snippets
namespace App\Models;
use Abhiaay\QueryCraft\QueryCraft;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Post extends Model
{
use HasFactory, QueryCraft;
/**
* @inheritdoc
*
* @return [alias => db_column]
*/
public function filterableColumns(): array
{
return [
'title' => 'title',
// for relation or embed for mongodb
'category' => 'category.id'
];
}
/**
* @inheritdoc
*/
public function sortableColumns(): array
{
return [
'created_at' => 'created_at',
// for relation or embed for mongodb
'category' => 'category.name'
];
}
}
namespace App\Http\Controllers;
use App\Models\Post;
use Illuminate\Http\Request;
use Abhiaay\QueryCraft\Craft;
class PostController extends Controller
{
public function index(Request $request)
{
$craft = Craft::parse($request);
return Post::craft($craft)->paginate($request->input('per_page'));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.