PHP code example of everestmx / nova-belongs-to-many-field
1. Go to this page and download the library: Download everestmx/nova-belongs-to-many-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/ */
everestmx / nova-belongs-to-many-field example snippets
use Everestmx\BelongsToManyField\BelongsToManyField;
public function fields(Request $request){
BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')
->options(\App\Role::all()),
}
use Everestmx\BelongsToManyField\BelongsToManyField;
public function fields(Request $request){
BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')
->options(\App\Role::all())
->optionsLabel('title'),
}
use Everestmx\BelongsToManyField\BelongsToManyField;
public function fields(Request $request){
BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')
->options(\App\Role::all())
->isAction(),
}
public function handle(ActionFields $fields, Collection $models)
{
// Get the expenseTypes from the request because the Field BelongsToManyField does not send it
$values = array_column(json_decode(request()->roles, true),'id');
foreach ($models as $model) {
$model->roles()->sync($values);
}
}
use Everestmx\BelongsToManyField\BelongsToManyField;
public function fields(Request $request){
BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')
->options(\App\Role::all())
->relationModel(\App\User::class)
->rules('
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.