PHP code example of webfactor / laravel-backpack-instant-fields

1. Go to this page and download the library: Download webfactor/laravel-backpack-instant-fields 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/ */

    

webfactor / laravel-backpack-instant-fields example snippets




use Webfactor\Laravel\Backpack\InstantFields\InstantFields;

class EntityCrudController extends CrudController
{
    use InstantFields;

    //
}

 
 
CRUD::resource('entity', 'EntityCrudController')->with(function () {
    Route::any('entity/ajax/{mode?}', 'EntityCrudController@handleAjaxRequest');
});
 



use Webfactor\Laravel\Backpack\InstantFields\InstantFields;

class EntityCrudController extends CrudController
{
   use InstantFields;

   public function setup()
   {
       // other Backpack options
       
       $this->setAjaxEntity('entity');
       
       // fields/columns definitions
   }
}



    $this->addInstantCreateButtonToList(
        $entity, // foreign entity 
        $content, // content of the button
        $entity_id, // the name of the ID of the current entity will be forwarded by this  
        $class, // optional, default: 'btn btn-xs btn-default', the css class of the button
        $position, // optional, default: beginning, the position of the button in the line 
        $button_view // optional, you can override the used button blade by your own
    );
        
        // Example:
    
    $this->addInstantCreateButtonToList(
        'order', 
        '<i class="fa fa-cart-plus"></i>', 
        'task_id', 
        'btn btn-sm btn-info', 
        'end'
    );



use Webfactor\Laravel\Backpack\InstantFields\InstantFields;

class EntityCrudController extends CrudController
{
    use InstantFields;

    public function setup()
    {
        // other Backpack options
        
        $this->setAjaxEntity('entity');
        $this->setAjaxStoreRequest(\RequestNamespace\StoreRequest::class);
        $this->setAjaxUpdateRequest(\RequestNamespace\UpdateRequest::class);
        
        // fields/columns definitions
    }
}

'search_logic' => function($query, $searchTerm, $form) { // Collection $form is optional
    return $query->where('name', 'like', '%'.$searchTerm.'%')
                 ->whereActive()
                 ->whereSomethingElse();
},

php artisan vendor:publish --tag=instantfields