Created
October 10, 2018 19:05
-
-
Save breizhwave/b00caffddca41947a1f71f5789006685 to your computer and use it in GitHub Desktop.
backpack crudcontroller helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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