PHP code example of eloverde-sistemas / laravel-crud-builder

1. Go to this page and download the library: Download eloverde-sistemas/laravel-crud-builder 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/ */

    

eloverde-sistemas / laravel-crud-builder example snippets


  use CrudBuilder\CrudBuilder;
    
  $singer = CrudBuilder::for(Singer::class)
    ->allowedAttributes('age', 'name')
    ->create();
  
  //A singer is created in database with the request data 

  use CrudBuilder\CrudBuilder;
    
  $singer = CrudBuilder::for(Singer::class)
    ->allowedAttributes('age', 'name')
    ->update();
  
  //A singer with the requested id is updated in database with the request data 

  use CrudBuilder\CrudBuilder;
    
  $singer = CrudBuilder::for(Singer::class)
    ->ignoreAttributes('age', 'surname')
    ->allowedAttributes('name')
    ->update();
  
  //A singer with the requested id is updated in database with the request data, except the ignored attributes 

class SingerModel extends Model
{
  public function band()
  {
      return $this->belongsTo(Band::class);
  }
}

  use CrudBuilder\CrudBuilder;
    
  $singer = CrudBuilder::for(Singer::class)
    ->allowedAttributes('name')
    ->allowedRelations('band')
    ->update();
  
  //A singer with the requested id is updated in database with the request data, including the relationship