Skip to content

Instantly share code, notes, and snippets.

@G3z
Created June 23, 2021 13:37
Show Gist options
  • Save G3z/4f5fe4fc0fe579a8bc81ab18b675ec92 to your computer and use it in GitHub Desktop.
Save G3z/4f5fe4fc0fe579a8bc81ab18b675ec92 to your computer and use it in GitHub Desktop.
Orchid selection
@if($filters->count() > 0)
<div class="no-gutters bg-white p-4 rounded mb-3">
<a class="btn" data-bs-toggle="collapse" href="#collapse-filters" role="button" aria-expanded="false"
aria-controls="collapse-filters" data-bs-target="#collapse-filters">
<x-orchid-icon path="magnifier" class="me-2" /> Cerca
</a>
<div id="collapse-filters" class="collapse">
<div class="card card-body">
<div class="row align-items-center">
@foreach($filters->where('display', true) as $filter)
<div class="col-lg-4 align-self-start">
{!! $filter->render() !!}
</div>
@endforeach
</div>
<div class="ms-auto mt-4 text-right">
<div class="form-group">
<div class="btn-group" role="group">
<button data-action="screen--filter#clear" class="btn btn-default">
<x-orchid-icon path="ban" class="mr-2" /> Azzera
</button>
<button type="submit" form="filters" class="btn btn-default">
<x-orchid-icon path="filter" class="mr-2" /> Filtra
</button>
</div>
</div>
</div>
</div>
</div>
@foreach($filters as $filter)
@if($filter->display && $filter->isApply())
<a href="{{ $filter->resetLink() }}" class="badge badge-light me-1 p-1">
<x-orchid-icon path="ban" />{{$filter->value()}}
</a>
@endif
@endforeach
</div>
@endif
<?php
namespace Domain\Platform\Admin\Filters;
use Illuminate\Database\Eloquent\Builder;
use Orchid\Filters\Filter;
use Orchid\Screen\Fields\Input;
class NameFilter extends Filter
{
/**
* @var array
*/
public $parameters = ['name'];
/**
* @return string
*/
public function name(): string
{
return 'Nome';
}
/**
* @param Builder $builder
*
* @return Builder
*/
public function run(Builder $builder): Builder
{
return $builder->where('name', 'ILIKE', '%' . $this->request->get('name') . '%');
}
/**
* @return Field[]
*/
public function display(): array
{
return [
Input::make('name')
->type('text')
->value($this->request->get('name'))
->placeholder('Cerca per nome')
->title('Nome'),
];
}
}
<?php
declare (strict_types = 1);
namespace Domain\Commerce\Admin\Screens\Product;
use Domain\Commerce\Admin\Layouts\Product\ProductListLayout;
use Domain\Commerce\Admin\Layouts\Product\ProductSelection;
class ProductListScreen extends Screen
{
/**
* Views.
*
* @return Layout[]
*/
public function layout(): array
{
return [
ProductSelection::class,
ProductListLayout::class,
];
}
}
<?php
namespace Domain\Commerce\Admin\Layouts\Product;
use Domain\Commerce\Admin\Filters\Product\CategoryFilter;
use Domain\Commerce\Admin\Filters\Product\PriceFilter;
use Domain\Platform\Admin\Filters\NameFilter;
use Orchid\Filters\Filter;
use Orchid\Screen\Layouts\Selection;
class ProductSelection extends Selection
{
/**
* @var string
*/
public $template = 'platform.admin.selection.accordion';
/**
* @return Filter[]
*/
public function filters(): array
{
return [
NameFilter::class,
CategoryFilter::class,
PriceFilter::class,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment