# Resource Lists

# What are the available resource lists?

<table border="1" id="bkmrk-class-view-%5Caero%5Cadm" style="border-collapse: collapse; width: 100%; height: 1281.27px;"><colgroup><col style="width: 56.6167%;"></col><col style="width: 43.3833%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Class**  
</td><td style="height: 29.7969px;">**View**  
</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\AttributeGroupsResourceList`  
</td><td style="height: 29.7969px;">`admin::resource-lists.index`  
</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\BlocksResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CategoriesResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CollectionsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CombinationsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CountriesResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CountryGroupsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CurrenciesResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CustomerGroupsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CustomersResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\CustomerTaxGroupsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\DeletedProductsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\DiscountsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\ExportLogsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\FlagsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\FulfillmentMethodsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\FulfillmentsResourceList`</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\LocationsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\MailNotificationsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\ManufacturersResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\MissingPagesResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\OrderReturnReasonGroupsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\OrdersResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\OrderStatusesResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\OrderStatusGroupsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\PagesResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\PaymentMethodsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\PriceListsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\ProductsResourceList`

</td><td style="height: 29.7969px;">`admin::catalog.products.index`  
</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\ProductTaxGroupsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\ProductTypesResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\RedirectsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\SettingDefinitionsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\ShippingMethodsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\SubscriptionActionsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\SubscriptionPlansResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\SubscriptionsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\TagGroupsResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\TaxRatesResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\TaxRulesResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\UsersResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">`\Aero\Admin\ResourceLists\VouchersResourceList`

</td><td style="height: 29.7969px;">`admin::resource-lists.index`</td></tr></tbody></table>

# How do I create a custom resource list?

To create a resource list you need a normal Laravel controller and a class that extends `Aero\Admin\ResourceListsAbstractResourceList`.

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
   //
}
```

Your controller should be like this example but for your new resource list:

```php
class OrdersController extends \Aero\Admin\Http\Controllers\Controller
{
   public function index(\Aero\Admin\ResourceLists\OrdersResourceList $list, \Illuminate\Http\Request $request)
   {
       return view('admin::resource-lists.index', [
           'list' => $list = $list(),
           'results' => $list->apply($request->all())
               ->with('status', 'customer', 'items', 'currency')
               ->paginate($request->input('per_page', 24) ?? 24),
       ]);
   }
}
```

## Columns

To add columns to your resource list you need to implement the protected `columns()` method and make it return an `array` of your columns.

The entries in the array should use the `Aero\Admin\ResourceLists\ResourceListColumn::create()` helper method. This method expects a string parameter for the columns heading, a closure parameter for how to render the columns data (this can return a string), and an optional string parameter for the columns key (by default this is generated from the columns header):

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
    protected function columns(): array
    {
        return [
            \Aero\Admin\ResourceLists\ResourceListColumn::create('Order', function ($row) {
                return view('admin::resource-lists.link', [
                    'route' => route('admin.orders.view', array_merge(request()->all(), ['order' => $row])),
                    'text' => '#'.$row->reference,
                ])->render();
            }),
        ];
    }
}
```

### Searchable Columns

You can use the `setSearchAction()` method to define how your column is searched:

```php
ResourceListColumn::create('Order', function ($row) {
    return view('admin::resource-lists.link', [
        'route' => route('admin.orders.view', array_merge(request()->all(), ['order' => $row])),
        'text' => '#'.$row->reference,
    ])->render();
})
->setSearchAction(function ($query, $term) {
    $searchTerm = ltrim($search, '#');
  
    $query->whereLower('reference', 'like', "%{$searchTerm}%");
}, 'Order Reference')
```

### Invisible Columns

You can use the `invisible()` method to make a column invisible. This can be useful if wanting to add a search action but not display the relevant data.

### Rows

Row views are additional rows rendered after each complete row (the best example of this is how the order items are listed after each row of the order on the orders page). To add a row view you simply need to provide your view in the protected `$rowViews` array:

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
    protected $rowViews = [
        'admin::resource-lists.orders.items',
    ];
}
```

### Default Search

When your resource list is searched without a specific column being selected a `handleSearch()` method will be called to handle searching.

The method will be passed the search term and you can use `$this->query` to access the query:

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
    protected function handleSearch($search)
    {
        $searchTerm = ltrim($search, '#');

        $this->query->whereLower('reference', 'like', "%{$searchTerm}%");
    }
}
```

### Buttons

Most resource list pages will require a create button, typically a create resource button. You can easily add buttons to the top of your resource list page by defining a header slot. Once you have defined a header slot you can inject your view using the admin slots helper.

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
    protected $headerSlot = 'orders.index.header.buttons';
}
```

<p class="callout info">See [here](https://support.aerocommerce.com/books/admin/page/how-do-i-inject-into-admin-slots) for how to inject into admin slots.</p>

### Filters

To add a filter to your resource list, simply add it to the `$filters` array:

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
    protected $filters = [
        \Aero\Admin\Filters\Order\OrderStatusAdminFilter::class,
    ];
}
```

<p class="callout info">See [here](https://support.aerocommerce.com/books/admin/page/what-filter-types-are-available) for how to create an existing admin filter, or [here](https://support.aerocommerce.com/books/admin/page/how-do-i-create-a-custom-admin-filter) for how to create a custom filter.</p>

### Sort Bys

To add sort bys to your resource list you need to implement the protected `sortBys()` method and make it return an `array` of your sort bys.

The entries in the array should use the `Aero\Admin\ResourceLists\ResourceListSortBy::create()` helper method. This method expects an array parameter holding the dropdown options that will be shown in the frontend dropdown, and a closure that will be executed when the sort option is active:

```php
class OrdersResourceList extends \Aero\Admin\ResourceLists\AbstractResourceList
{
    protected function sortBys(): array
    {
        return [
            // Default sort by
            \Aero\Admin\ResourceLists\ResourceListSortBy::create(null, function ($sortBy, $query) {
                return $query->orderByRaw('coalesce(`orders`.`ordered_at`, `orders`.`created_at`) desc');
            }),

            \Aero\Admin\ResourceLists\ResourceListSortBy::create([
                'order-az' => 'Order A to Z',
                'order-za' => 'Order Z to A',
            ], function ($sortBy, $query) {
                return $sortBy === 'order-az' ? $query->orderBy('reference') : $query->orderByDesc('reference');
            }),
        ];
    }
}

```

# How do I add a column to an existing resource list?

You can use the `addColumn()` method(s) to add a column to an existing resource list:

```php
\Aero\Admin\ResourceLists\OrdersResourceList::extend(function (\Aero\Admin\ResourceLists\OrdersResourceList $list, \Closure $next) {
    // Add it as the first column
    $list->addColumn('Header', function($row) {
        return 'Content';
    });

    // Add it after a specific column
    $list->addColumnAfter('Header', function($row) {
        return $row->reference;
    }, 'customer');

    // Add it before a specific column
    $list->addColumnBefore('Header', function($row) {
        return $row->reference;
    }, 'customer');

    return $next($list);
});

```

If you need to see the keys of the existing columns in order to position your new column appropriately, you can dump them out:

```php
\Aero\Admin\ResourceLists\OrdersResourceList::extend(function (\Aero\Admin\ResourceLists\OrdersResourceList $list, \Closure $next) {
    dd($list->getColumns()->map->key());

    return $next($list);
});
```

# How do I add a filter to an existing resource list?

You can use the `addFilter()` method to add a filter to an existing resource list:

```php
\Aero\Admin\ResourceLists\OrdersResourceList::extend(function (\Aero\Admin\ResourceLists\OrdersResourceList $list, \Closure $next) {
    $list->addFilter(\Aero\Admin\Filters\Order\OrderStatusAdminFilter::class);

    return $next($list);
});
```

# How do I add a sort by to an existing resource list?

You can use the `addSortBy()` method to add a filter to an existing resource list:

```php
\Aero\Admin\ResourceLists\OrdersResourceList::extend(function (\Aero\Admin\ResourceLists\OrdersResourceList $list, \Closure $next) {
    $list->addSortBy(\Aero\Admin\ResourceLists\ResourceListSortBy::create([
        'latest' => 'Latest',
        'oldest' => 'Oldest',
    ], function ($sortBy, $query) {
        return $sortBy === 'oldest' ? $query->orderBy('created_at') : $query->orderByDesc('created_at');
    }));

    return $next($list);
});
```

# How do I create a custom bulk action?

You can create a class that extends `\Aero\Admin\BulkActions\BulkActionJob` and implement a `handle` method:

```
class DeleteProductsBulkAction extends \Aero\Admin\BulkActions\BulkActionJob
    implements \Illuminate\Contracts\Queue\ShouldQueue
{
    protected $list;

    public function __construct(\Aero\Admin\ResourceLists\ProductsResourceList $list)
    {
        $this->list = $list;
    }

    public function handle(): void
    {
        $this->list->items()->each(static function (\Aero\Catalog\Models\Product $product) {
            $product->delete();
            event(new \Aero\Catalog\Events\ProductDeleted($product));
        });
    }
}
```

<p class="callout info">You should implement `\Illuminate\Contracts\Queue\ShouldQueue` if you want the bulk action to be queued.</p>

# How do I add a bulk action to an existing resource list?

```php
\Aero\Admin\BulkAction::create(
  \Aero\Admin\BulkActions\DeleteProductsBulkAction::class, 
  \Aero\Admin\ResourceLists\ProductsResourceList::class
)
->title('Delete products')
->permissions('products.delete')
->confirm();
```

<p class="callout info">See [here](https://support.aerocommerce.com/books/admin/page/how-do-i-create-a-custom-bulk-action) for how to create a custom bulk action.</p>

---

### Methods

<table border="1" id="bkmrk-method-description-n" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50.0596%;"></col><col style="width: 50.0596%;"></col></colgroup><tbody><tr><td>**Method**</td><td>**Description**</td></tr><tr><td>`notRunnable()`  
</td><td>Removes the `run` button from the bulk action, intention being you replace this with a custom button.</td></tr><tr><td>`wideContent()`  
</td><td>Displays bulk action view in a wider container.</td></tr><tr><td>`confirm()`  
</td><td>Prompts the user to confirm running the bulk action.</td></tr><tr><td>`confirmTitle(string $title)`  
</td><td>Sets the title of the confirmation popup. Default is "Are you sure?</td></tr><tr><td>`confirmText(string $text)`  
</td><td>Sets text in the confirmation popup. Default is no text.</td></tr><tr><td>`confirmButtonText(string $text)`  
</td><td>Sets the confirmation popup confirm button text. Default is "Yes".</td></tr><tr><td>`title(string $title)`  
</td><td>Sets the title of the bulk action.</td></tr><tr><td>`processingText(string $text)`  
</td><td>Sets the processing text (shown when a bulk action is queued). Default is `__('Bulk action is being processed')`.</td></tr><tr><td>`successText(string $text)`  
</td><td>Sets the success text (shown when a bulk action is ran). Default is `__('Bulk action has been processed')`.</td></tr><tr><td>`view(string $view)`  
</td><td>Sets a view for the bulk action to redirect to when ran. Allows options to be provided that are required for the bulk action to run.</td></tr><tr><td>`group(string $group)`  
</td><td>Sets the group of the bulk action, used when they're displayed to order them.</td></tr></tbody></table>