Skip to content

Instantly share code, notes, and snippets.

@breizhwave
Created October 10, 2018 19:05
Show Gist options
  • Save breizhwave/b00caffddca41947a1f71f5789006685 to your computer and use it in GitHub Desktop.
Save breizhwave/b00caffddca41947a1f71f5789006685 to your computer and use it in GitHub Desktop.
backpack crudcontroller helper
<?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
// VALIDATION: change the requests to match your own file names if you need form validation
use App\Http\Requests\WaveResourceRequest as StoreRequest;
use App\Http\Requests\WaveResourceRequest as UpdateRequest;
class WaveCrudController extends CrudController
{
public function addBothField($arr, $blnListHide=0)
{
$arrColumns=$arr;
$arrColumns["type"]=str_replace("select2_multiple","select_multiple",$arrColumns["type"]);
if (!$blnListHide)$this->crud->addColumn($arrColumns);
$this->crud->addField($arr );
}
public function addBothSelectField($arr, $blnListHide=0)
{
$model = $arr["model"];
$this->addBothField( ['label' => ucfirst($model),
'type' => 'select',
'name' => strtolower($model) . '_id',
'entity' => strtolower($model) ,
'attribute' => 'name',
'model' => "App\Models\Wave" . ucfirst($model)]
,$blnListHide);
}
public function addSelectFilter($field, $class, $name)
{
$model="\\App\\Models\\" . $class;
$values = $model::all()->pluck('name', 'id')->toArray();
$this->crud->addFilter([ // select2 filter
'name' => $field,
'type' => 'select2',
'label'=> $name
], $values
// , function($value) { // if the filter is active$this->crud->addClause('where', $filter->name, $value);}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment