Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. User (id, name, department_id)
  2. Department (id, name)
  3.  
  4. +----+-------------+--------------+
  5. | id | name | department |
  6. +----+-------------+--------------+
  7. | 1 | User 1 | 1 |
  8. +----+-------------+--------------+
  9.  
  10. +----+-------------+--------------+
  11. | id | name | department_id|
  12. +----+-------------+--------------+
  13. | 1 | User 1 | Department 1 |
  14. +----+-------------+--------------+
  15.  
  16. User.php
  17.  
  18. public function _department() {
  19. return $this->belongsTo('AppModelsDepartment','id');
  20. }
  21.  
  22. Department.php
  23.  
  24. public function _user() {
  25. return $this->hasMany('AppModelsUser','department_id');
  26. }
  27.  
  28. class UserCrudController extends CrudController
  29. {
  30. public function setup()
  31. {
  32. /*
  33. |-----------------------------------------------------------------------
  34. | CrudPanel Basic Information
  35. |-----------------------------------------------------------------------
  36. */
  37. $this->crud->setModel('AppModelsUser');
  38. $this->crud->setRoute(config('backpack.base.route_prefix') . '/user');
  39. $this->crud->setEntityNameStrings('', 'User');
  40. $this->crud->allowAccess('list');
  41.  
  42. /*
  43. |-----------------------------------------------------------------------
  44. | CrudPanel Configuration
  45. |-----------------------------------------------------------------------
  46. */
  47. $this->crud->addColumns([
  48. [
  49. 'name' => 'id',
  50. 'label' => "ID",
  51. 'type' => 'text',
  52. ],
  53. [
  54. 'name' => 'name',
  55. 'label' => "Name",
  56. ],
  57. [
  58. 'name' => 'department_id',
  59. 'type' => 'text',
  60. 'label' => 'Department',
  61. 'entity' => '_department',
  62. 'attribute' => 'name',
  63. 'model' => 'AppModelsDepartment'
  64. ],
  65. ]);
  66.  
  67. $this->crud->setRequiredFields(StoreRequest::class, 'create');
  68. $this->crud->setRequiredFields(UpdateRequest::class, 'edit');
  69. }
  70.  
  71. public function store(StoreRequest $request)
  72. {
  73. // your additional operations before save here
  74. $redirect_location = parent::storeCrud($request);
  75. // your additional operations after save here
  76. // use $this->data['entry'] or $this->crud->entry
  77. return $redirect_location;
  78. }
  79.  
  80. public function update(UpdateRequest $request)
  81. {
  82. // your additional operations before save here
  83. $redirect_location = parent::updateCrud($request);
  84. // your additional operations after save here
  85. // use $this->data['entry'] or $this->crud->entry
  86. return $redirect_location;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement