PHP code example of orlyapps / nova-belongsto-depend
1. Go to this page and download the library: Download orlyapps/nova-belongsto-depend 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/ */
orlyapps / nova-belongsto-depend example snippets
use Orlyapps\NovaBelongsToDepend\NovaBelongsToDepend;
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('Name')->rules('pp\Company::all()),
NovaBelongsToDepend::make('Department')
->placeholder('Optional Placeholder') // Add this just if you want to customize the placeholder
->optionsResolve(function ($company) {
// Reduce the amount of unnecessary data sent
return $company->departments()->get(['id','name']);
})
->dependsOn('Company'),
NovaBelongsToDepend::make('Location')
->placeholder('Optional Placeholder') // Add this just if you want to customize the placeholder
->optionsResolve(function ($company) {
// Reduce the amount of unnecessary data sent
return $company->locations()->get(['id','name']);
})
->fallback(
Text::make('Location Name')->rules('
/**
* @return mixed
*/
public function getNameAttribute()
{
return $this->getTranslations('name')[app()->getLocale()];
}
class Company extends Resource
{
public static $with = [];
}
class Department extends Resource
{
public static $with = ['company'];
}
class Location extends Resource
{
public static $with = ['department', 'company'];
}