Skip to main content

Glue

This module allows you to link multiple different resources to your own resources in a single field.

Installation

composer require qore/glue

After you installed the module publish its contents:

php artisan vendor:publish --tag=qore.glue.db --force
php artisan vendor:publish --tag=qore.glue.frontend --force

Optionally, the config:

php artisan vendor:publish --tag=qore.glue.config

After you have published the contents of the module run the migrations:

php artisan tenants:migrate

After you have installed the module you need to enable it in your Qore application.

Usage

Model

Add the following interface and trait to the model of your resource:

class MyModel extends Model implements LinksResourcesContract
{
use LinksResources;

Field

You can now add the following field. The name doesn't matter.

LinkResources::make('Linked resources', 'linked_resources')

There are two ways to specify which resources can be linked, to make all resources linkable:

LinkResources::make('Linked resources', 'linked_resources')
->withLinkableResources();

Or specify which resources can be linked manually (specify names):

LinkResources::make('Linked resources', 'linked_resources')
->withLinkableResources([
'sales_leads',
'sales_deals',
'users',
]);

Permissions

This module will automatically check if you can view the linked resources. If you don't have the viewAny permissions, the resource will not be selectable in the field. If someone else linked a resource you don't have permission to view, you will only be able to see it's title.

Manually retrieving linked resources

You can retrieve the linked resources like this:

$myModel->retrieveLinkedResourceModels()

Keep in mind that this will always execute queries.

Indirect linked resources

You can also retrieve resources that are "indirectly" linked:

$myModel->retrieveIndirectLinkedResourceModels()

Or retrieve all linked resources, both direct and indirect:

$myModel->retrieveLinkedAndIndirectLinkedResourceModels()

Predetermined table filters

By default, only the organization resource fields will be pre-filtered in the table. For example, when you want to link a ContactPerson to a SalesLead, the organization column is automatically filtered.

'filters_to_match' => [
'resource_names' => [
'organizations',
],
],