PHP code example of dive-be / nova-linkable-field

1. Go to this page and download the library: Download dive-be/nova-linkable-field 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/ */

    

dive-be / nova-linkable-field example snippets


use Dive\Nova\Linkable\Linkable;

Linkable::make('URL', 'url')
    ->withLinkable(
        Page::class, // the related model that is linked
        'CMS Page', // how the model is identified to the user
        ['title'], // columns queried for use in the callback (next parameter)
        fn ($page) => $page->getAttribute('title') // callback that resolves the display value of the related model
    ),

use InteractsWithLinks;

use \Dive\Nova\Linkable\LinkedCollection;

// Load the target relationships and attributes in as few queries as possible
$menuItems = LinkedCollection::create(MenuItem::all())
    ->loadLinkedData(['url']);

// Access the target (returns a model)
$menuItems->first()->linkedTargets['url'];

// Access the attribute (returns a value by calling `getLinkableValue()` on the linked target model)
$menuItems->first()->linkedAttributes['url'];
bash
php artisan vendor:publish --provider="Dive\Nova\Linkable\FieldServiceProvider"