PHP code example of internetguru / laravel-model-browser
1. Go to this page and download the library: Download internetguru/laravel-model-browser 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/ */
internetguru / laravel-model-browser example snippets
// Auto-applied filter (no manual code needed):
'name' => ['type' => 'string', 'label' => 'Name', 'column' => 'name']
// Manual filter (applied in your model scope via HasModelBrowserFilters):
'price' => ['type' => 'number', 'label' => 'Price']
use Internetguru\ModelBrowser\Traits\HasModelBrowserFilters;
class Order extends Model
{
use HasModelBrowserFilters;
protected string $modelBrowserFilterSessionKey = 'order_filter';
public static function summary()
{
$query = static::with(['customer', 'payment', 'charges']);
$price = (new static)->getModelBrowserFilterRange('price');
// Manual filter: price is a computed sum of related charges
if ($price['from'] !== null) {
$query->whereRaw(
'(SELECT SUM(amount) FROM charges WHERE charges.order_id = orders.id) >= ?',
[$price['from'] * 100]
);
}
if ($price['to'] !== null) {
$query->whereRaw(
'(SELECT SUM(amount) FROM charges WHERE charges.order_id = orders.id) <= ?',
[$price['to'] * 100]
);
}
return $query;
}
}
sh
php artisan vendor:publish --tag=config --provider="Internetguru\ModelBrowser\ModelBrowserServiceProvider"
php artisan vendor:publish --tag=views --provider="Internetguru\ModelBrowser\ModelBrowserServiceProvider"
php artisan vendor:publish --tag=translations --provider="Internetguru\ModelBrowser\ModelBrowserServiceProvider"
# If you want to publish everything, you can use the `--provider` option:
php artisan vendor:publish --provider="Internetguru\ModelBrowser\ModelBrowserServiceProvider"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.