1. Go to this page and download the library: Download novabytes/laravel-odata 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/ */
novabytes / laravel-odata example snippets
use NovaBytes\OData\Laravel\ODataQueryBuilder;
class ProductController extends Controller
{
public function index(Request $request)
{
return ODataQueryBuilder::for(Product::class, $request)
->allowedFilters('name', 'price', 'is_active', 'category_id')
->allowedSorts('name', 'price', 'created_at')
->allowedExpands('category', 'reviews')
->allowedSelects('id', 'name', 'price', 'description', 'category_id')
->get();
}
}
// Allowlists are loaded from config automatically
ODataQueryBuilder::for(Product::class, $request)->get();
// Explicit calls still override config when you need to restrict further
ODataQueryBuilder::for(Product::class, $request)
->allowedFilters('name') // overrides config for this endpoint
->get();