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 0000000..4125f00 Binary files /dev/null and b/public/import/assets/post-pic-dummy.png differ 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)