Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.37 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppModels;
  4.  
  5. use IlluminateDatabaseEloquentModel;
  6. use BackpackCRUDCrudTrait;
  7.  
  8. class Theme extends Model
  9. {
  10. use CrudTrait;
  11.  
  12. /*
  13. |--------------------------------------------------------------------------
  14. | GLOBAL VARIABLES
  15. |--------------------------------------------------------------------------
  16. */
  17.  
  18. protected $table = 'themes';
  19. //protected $primaryKey = 'id';
  20. // public $timestamps = false;
  21. // protected $guarded = ['id'];
  22. protected $fillable = ['name'];
  23. // protected $hidden = [];
  24. // protected $dates = [];
  25.  
  26. /*
  27. |--------------------------------------------------------------------------
  28. | FUNCTIONS
  29. |--------------------------------------------------------------------------
  30. */
  31.  
  32. /*
  33. |--------------------------------------------------------------------------
  34. | RELATIONS
  35. |--------------------------------------------------------------------------
  36. */
  37.  
  38. public function Theme() {
  39. return $this->hasMany('AppModelsEvent');
  40. }
  41.  
  42. /*
  43. |--------------------------------------------------------------------------
  44. | SCOPES
  45. |--------------------------------------------------------------------------
  46. */
  47.  
  48. /*
  49. |--------------------------------------------------------------------------
  50. | ACCESORS
  51. |--------------------------------------------------------------------------
  52. */
  53.  
  54. /*
  55. |--------------------------------------------------------------------------
  56. | MUTATORS
  57. |--------------------------------------------------------------------------
  58. */
  59. }
  60.  
  61. <?php
  62.  
  63. namespace AppModels;
  64.  
  65. use IlluminateDatabaseEloquentModel;
  66. use BackpackCRUDCrudTrait;
  67.  
  68. class Event extends Model
  69. {
  70. use CrudTrait;
  71.  
  72. /*
  73. |--------------------------------------------------------------------------
  74. | GLOBAL VARIABLES
  75. |--------------------------------------------------------------------------
  76. */
  77.  
  78. protected $table = 'events';
  79. //protected $primaryKey = 'id';
  80. // public $timestamps = false;
  81. // protected $guarded = ['id'];
  82. protected $fillable = ['name','theme','schedules','themeID','countyID','event_typeID','offered_conditionID','alone_with_typeID','tagID',
  83. 'advertiserID','event_languageID','special_priceID','start_date','end_date','price','photos','space_name','address','description','facebook_url',
  84. 'external_url1','featured_image','available_vacancies','gps_coordinates','external_url2','featured','status','start_featured_date','end_featured_date'];
  85.  
  86. // protected $hidden = [];
  87. // protected $dates = [];
  88.  
  89. /*
  90. |--------------------------------------------------------------------------
  91. | FUNCTIONS
  92. |--------------------------------------------------------------------------
  93. */
  94.  
  95. /*
  96. |--------------------------------------------------------------------------
  97. | RELATIONS
  98. |--------------------------------------------------------------------------
  99. */
  100.  
  101. public function Event() {
  102. return $this->hasOne('AppModelsEventSubType');
  103. return $this->hasMany('AppModelsSpecialPrice');
  104. return $this->hasMany('AppModelsPriceTypes');
  105. return $this->hasMany('AppModelsTag');
  106. // return $this->hasMany('AppModelsCounty');
  107. return $this->hasMany('AppModelsCounty');
  108. return $this->hasMany('AppModelsEventHasSpecialPrice');
  109. }
  110.  
  111. public function themes()
  112. {
  113. return $this->belongsToMany('AppModelsTheme');
  114. }
  115.  
  116. /*
  117. |--------------------------------------------------------------------------
  118. | SCOPES
  119. |--------------------------------------------------------------------------
  120. */
  121.  
  122. /*
  123. |--------------------------------------------------------------------------
  124. | ACCESORS
  125. |--------------------------------------------------------------------------
  126. */
  127.  
  128. /*
  129. |--------------------------------------------------------------------------
  130. | MUTATORS
  131. |--------------------------------------------------------------------------
  132. */
  133. }
  134.  
  135. <?php
  136.  
  137. namespace AppHttpControllersAdmin;
  138.  
  139. use BackpackCRUDappHttpControllersCrudController;
  140.  
  141. // VALIDATION: change the requests to match your own file names if you need form validation
  142. use AppHttpRequestsEventRequest as StoreRequest;
  143. use AppHttpRequestsEventRequest as UpdateRequest;
  144.  
  145. class EventCrudController extends CrudController
  146. {
  147.  
  148. public function setUp()
  149. {
  150.  
  151. /*
  152. |--------------------------------------------------------------------------
  153. | BASIC CRUD INFORMATION
  154. |--------------------------------------------------------------------------
  155. */
  156. $this->crud->setModel('AppModelsEvent');
  157. $this->crud->setRoute(config('backpack.base.route_prefix') . '/events');
  158. $this->crud->setEntityNameStrings('event', 'events');
  159.  
  160. /*
  161. |--------------------------------------------------------------------------
  162. | BASIC CRUD INFORMATION
  163. |--------------------------------------------------------------------------
  164. */
  165.  
  166. /* $this->crud->addColumn([
  167. 'label' => "Theme", // Table column heading
  168. 'type' => "select_multiple",
  169. 'name' => 'themes', // the column that contains the ID of that connected entity;
  170. 'entity' => 'themes', // the method that defines the relationship in your Model
  171. 'attribute' => "name", // foreign key attribute that is shown to user
  172. 'model' => 'AppModelsTheme', // foreign key model
  173. 'pivot' => true,
  174. ]); */
  175.  
  176. $this->crud->setFromDb();
  177.  
  178. $this->crud->addFields([
  179. // This is the field im trying to get working
  180. [
  181. 'label' => 'Theme',
  182. 'type' => 'select_multiple',
  183. 'name' => 'themeID',
  184. 'entity'=> 'Event',
  185. 'attribute' => 'name', // Column which user see in select box
  186. 'model' => 'AppModelsTheme' // Model which contain FK
  187. ],
  188. [
  189. 'label' => 'District',
  190. 'type' => 'select2',
  191. 'name' => 'countyID',
  192. 'entity'=> 'district',
  193. 'attribute' => 'name', // Column which user see in select box
  194. 'model' => 'AppModelsDistrict' // Model which contain FK
  195. ],
  196. [
  197. 'label' => 'Event Type',
  198. 'type' => 'select2',
  199. 'name' => 'event_typeID',
  200. 'entity'=> 'EventType',
  201. 'attribute' => 'name', // Column which user see in select box
  202. 'model' => 'AppModelsEventType' // Model which contain FK
  203. ],
  204. [
  205. 'label' => 'Offered Conditions',
  206. 'type' => 'select2',
  207. 'name' => 'offered_conditionID',
  208. 'entity'=> 'OfferedCondition',
  209. 'attribute' => 'name', // Column which user see in select box
  210. 'model' => 'AppModelsOfferedCondition' // Model which contain FK
  211. ],
  212. [
  213. 'label' => 'Alone With Types',
  214. 'type' => 'select2',
  215. 'name' => 'alone_with_typeID',
  216. 'entity'=> 'AloneWithType',
  217. 'attribute' => 'name', // Column which user see in select box
  218. 'model' => 'AppModelsAloneWithType' // Model which contain FK
  219. ],
  220. [
  221. 'label' => 'Tags',
  222. 'type' => 'select2',
  223. 'name' => 'tagID',
  224. 'entity'=> 'Tag',
  225. 'attribute' => 'name', // Column which user see in select box
  226. 'model' => 'AppModelsTag' // Model which contain FK
  227. ],
  228. [
  229. 'label' => 'Advertiser',
  230. 'type' => 'select2',
  231. 'name' => 'advertiserID',
  232. 'entity'=> 'Advertiser',
  233. 'attribute' => 'name', // Column which user see in select box
  234. 'model' => 'AppModelsAdvertiser' // Model which contain FK
  235. ],
  236. [
  237. 'label' => 'Event Language',
  238. 'type' => 'select2',
  239. 'name' => 'event_languageID',
  240. 'entity'=> 'Event_language',
  241. 'attribute' => 'name', // Column which user see in select box
  242. 'model' => 'AppModelsEventLanguage' // Model which contain FK
  243. ],
  244. [
  245. 'label' => 'Special Price',
  246. 'type' => 'select2',
  247. 'name' => 'special_priceID',
  248. 'entity'=> 'SpecialPrice',
  249. 'attribute' => 'name', // Column which user see in select box
  250. 'model' => 'AppModelsSpecialPrice' // Model which contain FK
  251. ]
  252. ]);
  253.  
  254. /* $this->crud->addField([
  255. 'label' => "Images",
  256. 'name' => "photos",
  257. 'type' => 'image_multiple',
  258. 'upload' => true,
  259. 'crop' => true, // set to true to allow cropping, false to disable
  260. 'aspect_ratio' => 0, // ommit or set to 0 to allow any aspect ratio
  261. ]); */
  262.  
  263. // $this->crud->addFields($array_of_arrays, 'update/create/both');
  264. // $this->crud->removeField('name', 'update/create/both');
  265. // $this->crud->removeFields($array_of_names, 'update/create/both');
  266.  
  267. // ------ CRUD COLUMNS
  268. // $this->crud->addColumn(); // add a single column, at the end of the stack
  269. // $this->crud->addColumns(); // add multiple columns, at the end of the stack
  270. // $this->crud->removeColumn('column_name'); // remove a column from the stack
  271. // $this->crud->removeColumns(['column_name_1', 'column_name_2']); // remove an array of columns from the stack
  272. // $this->crud->setColumnDetails('column_name', ['attribute' => 'value']); // adjusts the properties of the passed in column (by name)
  273. // $this->crud->setColumnsDetails(['column_1', 'column_2'], ['attribute' => 'value']);
  274.  
  275. // ------ CRUD BUTTONS
  276. // possible positions: 'beginning' and 'end'; defaults to 'beginning' for the 'line' stack, 'end' for the others;
  277. // $this->crud->addButton($stack, $name, $type, $content, $position); // add a button; possible types are: view, model_function
  278. // $this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position); // add a button whose HTML is returned by a method in the CRUD model
  279. // $this->crud->addButtonFromView($stack, $name, $view, $position); // add a button whose HTML is in a view placed at resourcesviewsvendorbackpackcrudbuttons
  280. // $this->crud->removeButton($name);
  281. // $this->crud->removeButtonFromStack($name, $stack);
  282.  
  283. // ------ CRUD ACCESS
  284. // $this->crud->allowAccess(['list', 'create', 'update', 'reorder', 'delete']);
  285. // $this->crud->denyAccess(['list', 'create', 'update', 'reorder', 'delete']);
  286.  
  287. // ------ CRUD REORDER
  288. // $this->crud->enableReorder('label_name', MAX_TREE_LEVEL);
  289. // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('reorder');
  290.  
  291. // ------ CRUD DETAILS ROW
  292. // $this->crud->enableDetailsRow();
  293. // NOTE: you also need to do allow access to the right users: $this->crud->allowAccess('details_row');
  294. // NOTE: you also need to do overwrite the showDetailsRow($id) method in your EntityCrudController to show whatever you'd like in the details row OR overwrite the views/backpack/crud/details_row.blade.php
  295.  
  296. // ------ REVISIONS
  297. // You also need to use VenturecraftRevisionableRevisionableTrait;
  298. // Please check out: https://laravel-backpack.readme.io/docs/crud#revisions
  299. // $this->crud->allowAccess('revisions');
  300.  
  301. // ------ AJAX TABLE VIEW
  302. // Please note the drawbacks of this though:
  303. // - 1-n and n-n columns are not searchable
  304. // - date and datetime columns won't be sortable anymore
  305. // $this->crud->enableAjaxTable();
  306.  
  307. // ------ DATATABLE EXPORT BUTTONS
  308. // Show export to PDF, CSV, XLS and Print buttons on the table view.
  309. // Does not work well with AJAX datatables.
  310. // $this->crud->enableExportButtons();
  311.  
  312. // ------ ADVANCED QUERIES
  313. // $this->crud->addClause('active');
  314. // $this->crud->addClause('type', 'car');
  315. // $this->crud->addClause('where', 'name', '==', 'car');
  316. // $this->crud->addClause('whereName', 'car');
  317. // $this->crud->addClause('whereHas', 'posts', function($query) {
  318. // $query->activePosts();
  319. // });
  320. // $this->crud->addClause('withoutGlobalScopes');
  321. // $this->crud->addClause('withoutGlobalScope', VisibleScope::class);
  322. // $this->crud->with(); // eager load relationships
  323. // $this->crud->orderBy();
  324. // $this->crud->groupBy();
  325. // $this->crud->limit();
  326. }
  327.  
  328. public function store(StoreRequest $request)
  329. {
  330.  
  331. /*
  332. // Setup storage
  333. $attribute_name = "photos";
  334. $disk = "uploads";
  335. $destination_path = "/uploads/projects";
  336.  
  337. // Then get images from request
  338. $input = $request->all();
  339. $images = $input[$attribute_name];
  340. $imageArray = [];
  341. // Now iterate images
  342. foreach ($images as $value) {
  343. // Store on disk and add to array
  344. if (starts_with($value, 'data:image'))
  345. {
  346. // 0. Make the image
  347. $image = Image::make($value);
  348. // 1. Generate a filename.
  349. $filename = md5($value.time()).'.jpg';
  350. // 2. Store the image on disk.
  351. Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
  352. // 3. Save the path to the database
  353. array_push($imageArray, $destination_path.'/'.$filename);
  354. }
  355. }
  356.  
  357. // Update $request with new array
  358. $request->request->set($attribute_name, $imageArray);
  359. */
  360. // Save $request
  361. $redirect_location = parent::storeCrud($request);
  362. // your additional operations after save here
  363. // use $this->data['entry'] or $this->crud->entry
  364. return $redirect_location;
  365. }
  366.  
  367. public function update(UpdateRequest $request)
  368. {
  369. // Setup storage
  370. $attribute_name = "images";
  371. $disk = "uploads";
  372. $destination_path = "/uploads/projects";
  373. // Then get images from request
  374. $input = $request->all();
  375. $images = $input[$attribute_name];
  376. $imageArray = [];
  377. // Now iterate images
  378. foreach ($images as $value) {
  379. // Store on disk and add to array
  380. if (starts_with($value, 'data:image'))
  381. {
  382. // 0. Make the image
  383. $image = Image::make($value);
  384. // 1. Generate a filename.
  385. $filename = md5($value.time()).'.jpg';
  386. // 2. Store the image on disk.
  387. Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
  388. // 3. Save the path to the database
  389. array_push($imageArray, $destination_path.'/'.$filename);
  390. } else {
  391. array_push($imageArray, $value);
  392. }
  393. }
  394. // Update $request with new array
  395. $request->request->set($attribute_name, $imageArray);
  396. // your additional operations before save here
  397. $redirect_location = parent::updateCrud($request);
  398. // your additional operations after save here
  399. // use $this->data['entry'] or $this->crud->entry
  400. return $redirect_location;
  401. }
  402.  
  403. /* public function store(StoreRequest $request)
  404. {
  405. // your additional operations before save here
  406. $redirect_location = parent::storeCrud();
  407. // your additional operations after save here
  408. // use $this->data['entry'] or $this->crud->entry
  409. return $redirect_location;
  410. }
  411.  
  412. public function update(UpdateRequest $request)
  413. {
  414. // your additional operations before save here
  415. $redirect_location = parent::updateCrud();
  416. // your additional operations after save here
  417. // use $this->data['entry'] or $this->crud->entry
  418. return $redirect_location;
  419. } */
  420. }
  421.  
  422. public function themes()
  423. {
  424. return $this->belongsToMany('AppModelsTheme');
  425. }
  426.  
  427. $this->crud->addFields([
  428. // This is the field im trying to get working
  429. [
  430. 'label' => 'Theme',
  431. 'type' => 'select_multiple',
  432. 'name' => 'themeID',
  433. 'entity'=> 'themes', // <-- this is the relation method name
  434. 'attribute' => 'name', // Column which user see in select box
  435. 'model' => 'AppModelsTheme' // Model which contain FK
  436. ],
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement