PHP code example of ericphamhoang / belongs-to-many-field
1. Go to this page and download the library: Download ericphamhoang/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/ */
ericphamhoang / belongs-to-many-field example snippets
use Benjacho\BelongsToManyField\BelongsToManyField;
public function fields(Request $request){
BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')->options(\App\Role::all()),
}
use Benjacho\BelongsToManyField\BelongsToManyField;
public function fields(Request $request){
BelongsToManyField::make('Role Label', 'roles', 'App\Nova\Role')->options(\App\Role::all())->optionsLabel('title'),
}
use Benjacho\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 Benjacho\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.