Adding Browser Fields to a Block

To attach other records inside a block, it is possible to use the browser field.

  • In a block, use the browser field:

File:

views/twill/blocks/products.blade.php

1@twillBlockTitle('Products')
2 
3<x-twill::browser
4 route-prefix="shop"
5 module-name="products"
6 name="products"
7 label="Products"
8 :max="10"
9/>
  • If the module you are browsing is not at the root of your admin, you should use the browser_route_prefixes array in the configuration in addition to routePrefix in the form field declaration:
1'block_editor' => [
2 ...
3 'browser_route_prefixes' => [
4 'products' => 'shop',
5 ],
6 ...
7],
  • When rendering the blocks on the frontend you can get the browser items selected in the block, by using the getRelated helper to retrieve the selected items. Example in a blade template:

File:

views/site/blocks/blockWithBrowser.blade.php

1@php
2 $selected_items = $block->getRelated('browserFieldName');
3@endphp