PHP code example of dynamicnet / many-to-many

1. Go to this page and download the library: Download dynamicnet/many-to-many 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/ */

    

dynamicnet / many-to-many example snippets

  
  use Juul\Fields\BelongsToMany;  
  

  
  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('
  
  use Juul\Fields\BelongsToMany;  
  

  
  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('
  
  use Juul\Fields\BelongsToMany;  
  

  
  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      BelongsToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('
  
  use Juul\Fields\MorphToMany;  
  

  
  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      MorphToMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('
  
  use Juul\Fields\MorphedByMany;  
  

  
  /**
   * Get the fields displayed by the resource.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return array
   */
  public function fields(Request $request)
  {
    return [
      MorphedByMany::make(__("Label"), 'relationName', RelatedResource::class)
          ->fields(function() {
              return [
                  Text::make('Price')
                          ->rules('

  ->fillUsing(function($pivots) {
      if(isset($pivots['options']) && is_array($pivots['options'])) {
          $pivots['options'] = json_encode($pivots['options']);
      }

      return $pivots;
  }),