From ae8402668ef2e25b11da9592bf6eb5f0044d10d5 Mon Sep 17 00:00:00 2001 From: Yasser Elgammal Date: Wed, 3 Apr 2024 15:04:47 +0200 Subject: [PATCH] Some Updates & Fix Seeder Issue --- app/Http/Requests/Admin/PageRequest.php | 8 ++++++++ app/Http/Requests/Admin/PostRequest.php | 10 +++++++++- app/Models/Post.php | 9 +++++++++ app/Models/User.php | 9 +++++++++ app/Providers/EventServiceProvider.php | 4 ++-- database/factories/PostFactory.php | 8 ++------ database/factories/SettingFactory.php | 2 +- .../2022_12_27_115916_create_posts_table.php | 2 +- .../2023_01_05_224832_create_settings_table.php | 4 ++-- public/import/assets/post-pic-dummy.png | Bin 0 -> 2810 bytes resources/views/admin/account/index.blade.php | 8 +------- resources/views/admin/layouts/admin.blade.php | 6 +----- resources/views/front/category.blade.php | 2 +- resources/views/front/index.blade.php | 2 +- resources/views/front/post.blade.php | 9 ++------- resources/views/front/tag.blade.php | 2 +- resources/views/layouts/blog.blade.php | 7 +------ 17 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 public/import/assets/post-pic-dummy.png diff --git a/app/Http/Requests/Admin/PageRequest.php b/app/Http/Requests/Admin/PageRequest.php index 16ac38e..1edbc8d 100644 --- a/app/Http/Requests/Admin/PageRequest.php +++ b/app/Http/Requests/Admin/PageRequest.php @@ -32,6 +32,14 @@ public function rules() 'content' => ['required', 'min:10'], 'navbar' => ['required', 'boolean'], 'footer' => ['required', 'boolean'], + 'user_id' => ['required', 'exists:users,id'] ]; } + + public function prepareForValidation() + { + $this->merge([ + 'user_id' => auth()->id() + ]); + } } diff --git a/app/Http/Requests/Admin/PostRequest.php b/app/Http/Requests/Admin/PostRequest.php index 9eb83bf..2b21f94 100644 --- a/app/Http/Requests/Admin/PostRequest.php +++ b/app/Http/Requests/Admin/PostRequest.php @@ -31,7 +31,15 @@ public function rules() 'slug' => ['required', Rule::unique('posts')->ignore($this?->post?->id)], 'status' => ['required', 'boolean'], 'image' => ['image', 'mimes:jpeg,png,jpg', 'max:2048', Rule::requiredIf(!$this?->post?->id)], - 'tags' => ['exists:tags,id'] + 'tags' => ['exists:tags,id'], + 'user_id' => ['required', 'exists:users,id'] ]; } + + public function prepareForValidation() + { + $this->merge([ + 'user_id' => auth()->id() + ]); + } } diff --git a/app/Models/Post.php b/app/Models/Post.php index 138298e..12dfbc5 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -34,6 +34,15 @@ public function getPreviousAttribute() return static::wherecategoryId($this->category_id)->where('id', '<', $this->id)->published()->orderBy('id', 'desc')->first(); } + public function getImageAttribute($value) + { + if (!$value) { + return asset('import/assets/post-pic-dummy.png'); + } + + return asset("storage/$value"); + } + public function category() { return $this->belongsTo(Category::class); diff --git a/app/Models/User.php b/app/Models/User.php index e4e1f26..3b1eba5 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -50,6 +50,15 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', ]; + public function getAvatarAttribute($value) + { + if (!$value) { + return asset('import/assets/profile-pic-dummy.png'); + } + + return asset("storage/$value"); + } + public function posts() { return $this->hasMany(Post::class); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index fc29bd3..12db681 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -30,8 +30,8 @@ class EventServiceProvider extends ServiceProvider */ public function boot() { - Page::observe(PageObserver::class); - Post::observe(PostObserver::class); + // Page::observe(PageObserver::class); + // Post::observe(PostObserver::class); } /** diff --git a/database/factories/PostFactory.php b/database/factories/PostFactory.php index e844745..9fefdc2 100644 --- a/database/factories/PostFactory.php +++ b/database/factories/PostFactory.php @@ -21,12 +21,8 @@ public function definition() { $title = fake()->sentence(); $slug = str($title)->slug(); - $images_posts_path = 'storage/app/public/images/posts'; - if (!File::exists($images_posts_path)) { - File::makeDirectory($images_posts_path); - } - + return [ 'user_id' => rand(1,10), 'category_id' => rand(1,5), @@ -34,7 +30,7 @@ public function definition() 'content' => fake()->paragraph(6), 'status' => fake()->boolean(), 'slug' => $slug, - 'image' => 'images/posts/' . fake()->image($images_posts_path,1000,500, null, false), + 'image' => null, 'content' => fake()->paragraph(), ]; } diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index 007dea5..3c5312b 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -20,7 +20,7 @@ public function definition() 'site_name' => fake()->word(), 'contact_email' => fake()->email(), 'description' => fake()->sentence(), - 'about' => fake()->paragraph(), + 'about' => fake()->paragraph(1), 'copy_rights' => fake()->sentence(), 'url_fb' => fake()->url(), 'url_twitter' => fake()->url(), diff --git a/database/migrations/2022_12_27_115916_create_posts_table.php b/database/migrations/2022_12_27_115916_create_posts_table.php index 1c80f21..9e9e576 100644 --- a/database/migrations/2022_12_27_115916_create_posts_table.php +++ b/database/migrations/2022_12_27_115916_create_posts_table.php @@ -18,7 +18,7 @@ public function up() $table->string('title'); $table->string('slug')->unique(); $table->text('content'); - $table->string('image'); + $table->string('image')->nullable(); $table->boolean('status'); $table->integer('views')->default(0); $table->foreignId('category_id')->constrained('categories')->onDelete('cascade'); diff --git a/database/migrations/2023_01_05_224832_create_settings_table.php b/database/migrations/2023_01_05_224832_create_settings_table.php index af5319a..2302dec 100644 --- a/database/migrations/2023_01_05_224832_create_settings_table.php +++ b/database/migrations/2023_01_05_224832_create_settings_table.php @@ -17,8 +17,8 @@ public function up() $table->id(); $table->string('site_name')->nullable(); $table->string('contact_email')->nullable(); - $table->string('description')->nullable(); - $table->string('about')->nullable(); + $table->text('description')->nullable(); + $table->text('about')->nullable(); $table->string('copy_rights')->nullable(); $table->string('url_fb')->nullable(); $table->string('url_insta')->nullable(); diff --git a/public/import/assets/post-pic-dummy.png b/public/import/assets/post-pic-dummy.png new file mode 100644 index 0000000000000000000000000000000000000000..4125f007fefa7a883778c24a9eeb6e87ea2d06be GIT binary patch literal 2810 zcmcgu`B&4&9*trvtx6QsC|fLoV4)z;0u~4^0Yu7TWhsdPEM=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JyLx8!Ysm2*18zWa?~(EBORAxiY%bH(wAFym z6`uAAZkFgyT&pFZPxciu8GB@Za#PL^)Cb&-tbu;cVM`Usmno1*vAYxHPfA-|(0C-w zvp;HewJi6WMp3T%yzgo)jGQBz%8bJC){5!m9sj~V4g`u$)9Ho#*}Ne&=6$yv(9b&% K-g++j&i?=zr;fb< literal 0 HcmV?d00001 diff --git a/resources/views/admin/account/index.blade.php b/resources/views/admin/account/index.blade.php index 4c9794f..ec6010d 100644 --- a/resources/views/admin/account/index.blade.php +++ b/resources/views/admin/account/index.blade.php @@ -15,14 +15,8 @@
@csrf @method('PUT') - - @if ($user->avatar == null) - - @else - - @endif diff --git a/resources/views/admin/layouts/admin.blade.php b/resources/views/admin/layouts/admin.blade.php index f79196d..e72a0ba 100644 --- a/resources/views/admin/layouts/admin.blade.php +++ b/resources/views/admin/layouts/admin.blade.php @@ -154,11 +154,7 @@ class="absolute w-full upgrade-btn bottom-0 active-nav-link text-white flex item
diff --git a/resources/views/front/category.blade.php b/resources/views/front/category.blade.php index f1301ea..6dc5ed5 100644 --- a/resources/views/front/category.blade.php +++ b/resources/views/front/category.blade.php @@ -7,7 +7,7 @@ @forelse ($posts as $post)
- image") }}" width="1000" height="500"> +
- image") }}" width="1000" height="500"> +
{{ $post->category->name }} diff --git a/resources/views/front/post.blade.php b/resources/views/front/post.blade.php index 554d3d9..e0c1470 100644 --- a/resources/views/front/post.blade.php +++ b/resources/views/front/post.blade.php @@ -8,7 +8,7 @@
- image") }}" width="1000" height="500"> +
{{ $post->category->name }} @@ -23,13 +23,8 @@ class="text-blue-700 text-sm font-bold uppercase pb-4">{{ $post->category->name {{-- author --}}
- @if ($post->user->avatar == null) - - @else - - @endif

{{ $post->user->name }}

diff --git a/resources/views/front/tag.blade.php b/resources/views/front/tag.blade.php index 6888b44..97d9f64 100644 --- a/resources/views/front/tag.blade.php +++ b/resources/views/front/tag.blade.php @@ -7,7 +7,7 @@ @forelse ($tags as $post)