PHP code example of aqjw / nova-belongs-to-dependency

1. Go to this page and download the library: Download aqjw/nova-belongs-to-dependency 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/ */

    

aqjw / nova-belongs-to-dependency example snippets


use Aqjw\BelongsToDependency\BelongsToDependency;
...
return [
    ...
    BelongsTo::make('Type'),
    
    BelongsToDependency::make('User')
        ->dependsOn('type', 'type_id')
    ...
];

BelongsToDependency::make('User')
    ->dependsOn('type', 'type_id'),

BelongsToDependency::make('User')
    ->dependsOn(['type', 'role']),

BelongsToDependency::make('User')
    ->dependsOn([
        'type' => 'type_id',
        'role' => 'role_id',
    ]),

BelongsTo::make('Country')
    ->searchable(),

BelongsToDependency::make('State')
    ->searchable()
    ->dependsOn('country'),

BelongsToDependency::make('City')
    ->searchable()
    ->dependsOn('state'),

BelongsToDependency::make('Product')
    ->dependsOn('category')
    ->buildQuery(function ($query, $values) {
        $query->where($values)
            ->where('status', 'active');
    }),

BelongsToDependency::make('Product')
    ->dependsOn('category')
    ->formatResource(function ($resource) {
        return [
            'display' => $resource->name,
            'value' => $resource->id,
            'group' => $resource->parent_category,
        ];
    })