From 4b52ff9bea441f23d8adf96886ec1dfab4e57488 Mon Sep 17 00:00:00 2001 From: merdiano Date: Sat, 24 Aug 2019 12:07:22 +0500 Subject: [PATCH] sliders, tags , admin manages all orginizers --- .../Admin/SliderCrudController.php | 83 +++++++++++++++++ .../Controllers/Admin/TagCrudController.php | 60 +++++++++++++ app/Http/Controllers/MyBaseController.php | 2 +- app/Http/Requests/SliderRequest.php | 56 ++++++++++++ app/Http/Requests/TagRequest.php | 56 ++++++++++++ app/Models/MyBaseModel.php | 3 + app/Models/Slider.php | 89 +++++++++++++++++++ app/Models/Tag.php | 62 +++++++++++++ ...2019_08_21_150536_create_sliders_table.php | 37 ++++++++ .../2019_08_22_121029_create_tags_table.php | 32 +++++++ ...19_08_22_121613_create_event_tag_table.php | 36 ++++++++ ...122009_create_category_tag_pivot_table.php | 33 +++++++ ...133621_add_reorder_to_categories_table.php | 35 ++++++++ ...51938_add_sub_category_to_events_table.php | 33 +++++++ ..._24_101305_add_is_admin_to_users_table.php | 32 +++++++ .../views/Shared/Layouts/Master.blade.php | 5 +- 16 files changed, 650 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/Admin/SliderCrudController.php create mode 100644 app/Http/Controllers/Admin/TagCrudController.php create mode 100644 app/Http/Requests/SliderRequest.php create mode 100644 app/Http/Requests/TagRequest.php create mode 100644 app/Models/Slider.php create mode 100644 app/Models/Tag.php create mode 100644 database/migrations/2019_08_21_150536_create_sliders_table.php create mode 100644 database/migrations/2019_08_22_121029_create_tags_table.php create mode 100644 database/migrations/2019_08_22_121613_create_event_tag_table.php create mode 100644 database/migrations/2019_08_22_122009_create_category_tag_pivot_table.php create mode 100644 database/migrations/2019_08_22_133621_add_reorder_to_categories_table.php create mode 100644 database/migrations/2019_08_22_151938_add_sub_category_to_events_table.php create mode 100644 database/migrations/2019_08_24_101305_add_is_admin_to_users_table.php diff --git a/app/Http/Controllers/Admin/SliderCrudController.php b/app/Http/Controllers/Admin/SliderCrudController.php new file mode 100644 index 00000000..27962fa4 --- /dev/null +++ b/app/Http/Controllers/Admin/SliderCrudController.php @@ -0,0 +1,83 @@ +crud->setModel('App\Models\Slider'); + $this->crud->setRoute(config('backpack.base.route_prefix') . '/slider'); + $this->crud->setEntityNameStrings('slider', 'sliders'); + + /* + |-------------------------------------------------------------------------- + | CrudPanel Configuration + |-------------------------------------------------------------------------- + */ + + // TODO: remove setFromDb() and manually define Fields and Columns + $this->crud->addColumns([ + ['name' => 'title','type' => 'text', 'label' => 'Title'], + ['name' => 'text','type' => 'text', 'label' => 'Text'], + ['name' => 'link','type' => 'text', 'label' => 'Link'], + ['name' => 'active','type' => 'boolean', 'label' => 'Active'], + ['name' => 'image','type' => 'text', 'label' => 'Image'], + ]); + $this->crud->addFields([ + ['name' => 'title','type' => 'text', 'label' => 'Title'], + ['name' => 'text','type' => 'text', 'label' => 'Text'], + ['name' => 'link','type' => 'text', 'label' => 'Link'], + ['name' => 'active','type' => 'checkbox', 'label' => 'Active'], + [ // image + 'label' => "Image", + 'name' => "image", + 'type' => 'image', + 'upload' => true, + //'crop' => true, // set to true to allow cropping, false to disable + //'aspect_ratio' => 2, // ommit or set to 0 to allow any aspect ratio + //'disk' => 'local', // in case you need to show images from a different disk +// 'prefix' => 'user_content/' // in case your db value is only the file name (no path), you can use this to prepend your path to the image src (in HTML), before it's shown to the user; + ], + + ]); + + // add asterisk for fields that are required in SliderRequest + $this->crud->setRequiredFields(StoreRequest::class, 'create'); + $this->crud->setRequiredFields(UpdateRequest::class, 'edit'); + } + + public function store(StoreRequest $request) + { + // your additional operations before save here + $redirect_location = parent::storeCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } + + public function update(UpdateRequest $request) + { + // your additional operations before save here + $redirect_location = parent::updateCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } +} diff --git a/app/Http/Controllers/Admin/TagCrudController.php b/app/Http/Controllers/Admin/TagCrudController.php new file mode 100644 index 00000000..a3773b82 --- /dev/null +++ b/app/Http/Controllers/Admin/TagCrudController.php @@ -0,0 +1,60 @@ +crud->setModel('App\Models\Tag'); + $this->crud->setRoute(config('backpack.base.route_prefix') . '/tag'); + $this->crud->setEntityNameStrings('tag', 'tags'); + + /* + |-------------------------------------------------------------------------- + | CrudPanel Configuration + |-------------------------------------------------------------------------- + */ + + // TODO: remove setFromDb() and manually define Fields and Columns + $this->crud->setFromDb(); + + // add asterisk for fields that are required in TagRequest + $this->crud->setRequiredFields(StoreRequest::class, 'create'); + $this->crud->setRequiredFields(UpdateRequest::class, 'edit'); + } + + public function store(StoreRequest $request) + { + // your additional operations before save here + $redirect_location = parent::storeCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } + + public function update(UpdateRequest $request) + { + // your additional operations before save here + $redirect_location = parent::updateCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } +} diff --git a/app/Http/Controllers/MyBaseController.php b/app/Http/Controllers/MyBaseController.php index d2e0a4a4..ef7096e1 100644 --- a/app/Http/Controllers/MyBaseController.php +++ b/app/Http/Controllers/MyBaseController.php @@ -34,7 +34,7 @@ class MyBaseController extends Controller /* * Share the organizers across all views */ - $organizers = Auth::user()->is_admin ? Organiser::all():Organiser::scope()->get(); + $organizers = Organiser::scope()->get(); View::share('organisers', $organizers); } diff --git a/app/Http/Requests/SliderRequest.php b/app/Http/Requests/SliderRequest.php new file mode 100644 index 00000000..6d62d927 --- /dev/null +++ b/app/Http/Requests/SliderRequest.php @@ -0,0 +1,56 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/TagRequest.php b/app/Http/Requests/TagRequest.php new file mode 100644 index 00000000..74f4076c --- /dev/null +++ b/app/Http/Requests/TagRequest.php @@ -0,0 +1,56 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/app/Models/MyBaseModel.php b/app/Models/MyBaseModel.php index 3b8e2323..c080843a 100644 --- a/app/Models/MyBaseModel.php +++ b/app/Models/MyBaseModel.php @@ -145,6 +145,9 @@ class MyBaseModel extends \Illuminate\Database\Eloquent\Model * //return $query; */ + if(Auth::user()->is_admin) + return $query; + if (!$accountId) { $accountId = Auth::user()->account_id; } diff --git a/app/Models/Slider.php b/app/Models/Slider.php new file mode 100644 index 00000000..7863e365 --- /dev/null +++ b/app/Models/Slider.php @@ -0,0 +1,89 @@ +delete($obj->image); + }); + } + /* + |-------------------------------------------------------------------------- + | RELATIONS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESORS + |-------------------------------------------------------------------------- + */ + public function setImageAttribute($value) + { + $attribute_name = "image"; + $disk = 'local'; // or use your own disk, defined in config/filesystems.php + $destination_path = "sliders"; // path relative to the disk above + // if the image was erased + if ($value==null) { + // delete the image from disk + \Storage::disk($disk)->delete($this->{$attribute_name}); + // set null in the database column + $this->attributes[$attribute_name] = null; + } + // if a base64 was sent, store it in the db + if (starts_with($value, 'data:image')) + { + // 0. Make the image + $image = \Image::make($value)->encode('jpg', 90); + // 1. Generate a filename. + $filename = md5($value.time()).'.jpg'; + // 2. Store the image on disk. + \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); + // 3. Save the public path to the database + // but first, remove "public/" from the path, since we're pointing to it from the root folder + // that way, what gets saved in the database is the user-accesible URL + $public_destination_path = Str::replaceFirst('public/', '', $destination_path); + $this->attributes[$attribute_name] = asset('user_content/'.$public_destination_path.'/'.$filename); + } + } + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/app/Models/Tag.php b/app/Models/Tag.php new file mode 100644 index 00000000..f345c8c4 --- /dev/null +++ b/app/Models/Tag.php @@ -0,0 +1,62 @@ +belongsToMany(\App\Models\Event::class); + } + /* + |-------------------------------------------------------------------------- + | SCOPES + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | ACCESORS + |-------------------------------------------------------------------------- + */ + + /* + |-------------------------------------------------------------------------- + | MUTATORS + |-------------------------------------------------------------------------- + */ +} diff --git a/database/migrations/2019_08_21_150536_create_sliders_table.php b/database/migrations/2019_08_21_150536_create_sliders_table.php new file mode 100644 index 00000000..f680144c --- /dev/null +++ b/database/migrations/2019_08_21_150536_create_sliders_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->string('title')->nullable(); + $table->string('text')->nullable(); + $table->string('image')->nullable(); + $table->string('link')->nullable(); + $table->boolean('active')->default(0); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('sliders'); + } +} diff --git a/database/migrations/2019_08_22_121029_create_tags_table.php b/database/migrations/2019_08_22_121029_create_tags_table.php new file mode 100644 index 00000000..a12e04a0 --- /dev/null +++ b/database/migrations/2019_08_22_121029_create_tags_table.php @@ -0,0 +1,32 @@ +increments('id'); + $table->string('name_ru')->unique(); + $table->string('name_tm')->unique(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tags'); + } +} diff --git a/database/migrations/2019_08_22_121613_create_event_tag_table.php b/database/migrations/2019_08_22_121613_create_event_tag_table.php new file mode 100644 index 00000000..ce563e8f --- /dev/null +++ b/database/migrations/2019_08_22_121613_create_event_tag_table.php @@ -0,0 +1,36 @@ +increments('id'); + $table->unsignedInteger('event_id'); + $table->unsignedInteger('tag_id'); + $table->foreign('event_id')->references('id')->on('events'); + $table->foreign('tag_id')->references('id')->on('tags'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('event_tag', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2019_08_22_122009_create_category_tag_pivot_table.php b/database/migrations/2019_08_22_122009_create_category_tag_pivot_table.php new file mode 100644 index 00000000..d007d495 --- /dev/null +++ b/database/migrations/2019_08_22_122009_create_category_tag_pivot_table.php @@ -0,0 +1,33 @@ +integer('category_id')->unsigned()->index(); + $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade'); + $table->integer('tag_id')->unsigned()->index(); + $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); + $table->primary(['category_id', 'tag_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('category_tag'); + } +} diff --git a/database/migrations/2019_08_22_133621_add_reorder_to_categories_table.php b/database/migrations/2019_08_22_133621_add_reorder_to_categories_table.php new file mode 100644 index 00000000..e8085024 --- /dev/null +++ b/database/migrations/2019_08_22_133621_add_reorder_to_categories_table.php @@ -0,0 +1,35 @@ +unsignedInteger('parent_id')->default(0)->nullable(); + $table->unsignedInteger('lft')->default(0); + $table->unsignedInteger('rgt')->default(0); + $table->unsignedInteger('depth')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('categories', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2019_08_22_151938_add_sub_category_to_events_table.php b/database/migrations/2019_08_22_151938_add_sub_category_to_events_table.php new file mode 100644 index 00000000..dfe06ee2 --- /dev/null +++ b/database/migrations/2019_08_22_151938_add_sub_category_to_events_table.php @@ -0,0 +1,33 @@ +unsignedInteger('sub_category_id')->nullable(); + $table->foreign('sub_category_id')->references('id')->on('categories'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('events', function (Blueprint $table) { + $table->dropColumn('sub_category_id'); + }); + } +} diff --git a/database/migrations/2019_08_24_101305_add_is_admin_to_users_table.php b/database/migrations/2019_08_24_101305_add_is_admin_to_users_table.php new file mode 100644 index 00000000..c67b91fc --- /dev/null +++ b/database/migrations/2019_08_24_101305_add_is_admin_to_users_table.php @@ -0,0 +1,32 @@ +boolean('is_admin')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('is_admin'); + }); + } +} diff --git a/resources/views/Shared/Layouts/Master.blade.php b/resources/views/Shared/Layouts/Master.blade.php index 3e5af7d6..1e8e850a 100644 --- a/resources/views/Shared/Layouts/Master.blade.php +++ b/resources/views/Shared/Layouts/Master.blade.php @@ -79,13 +79,12 @@ class="loadModal editUserModal" href="javascript:void(0);">@lang("Top.my_profile")
  • + @if(!auth()->user()->is_admin)
  • @lang("Top.account_settings")
  • - -
  • -
  • @lang("Top.feedback_bug_report")
  • + @endif()
  • @lang("Top.sign_out")