Skip to content

Commit

Permalink
Some Updates & Fix Seeder Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
YasserElgammal committed Apr 3, 2024
1 parent 8762faa commit ae84026
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 41 deletions.
8 changes: 8 additions & 0 deletions app/Http/Requests/Admin/PageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
}
}
10 changes: 9 additions & 1 deletion app/Http/Requests/Admin/PostRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
}
}
9 changes: 9 additions & 0 deletions app/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions database/factories/PostFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ 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),
'title' => $title,
'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(),
];
}
Expand Down
2 changes: 1 addition & 1 deletion database/factories/SettingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Binary file added public/import/assets/post-pic-dummy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 1 addition & 7 deletions resources/views/admin/account/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@
<form method="POST" action="{{ route('admin.account.update', $user->id) }}" enctype="multipart/form-data">
@csrf
@method('PUT')

@if ($user->avatar == null)
<img src="{{ asset('import/assets/profile-pic-dummy.png') }}"
class="rounded-full shadow h-32 w-32">
@else
<img src="{{ asset('storage') . '/' . $user->avatar }}"
<img src="{{ $user->avatar }}"
class="rounded-full shadow h-32 w-32">
@endif
<label class="ml-4 block text-sm text-gray-600" for="message">Choose Image: </label>
<input class="ml-2" type="file" id="myimage" name="avatar">
</div>
Expand Down
6 changes: 1 addition & 5 deletions resources/views/admin/layouts/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ class="absolute w-full upgrade-btn bottom-0 active-nav-link text-white flex item
<div x-data="{ isOpen: false }" class="relative w-1/2 flex justify-end">
<button @click="isOpen = !isOpen"
class="realtive z-10 w-12 h-12 rounded-full overflow-hidden border-4 border-gray-400 hover:border-gray-300 focus:border-gray-300 focus:outline-none">
@if ($user_avatar == null)
<img src="{{ asset('import/assets/profile-pic-dummy.png') }}">
@else
<img src="{{ asset('storage') . '/' . $user_avatar }}">
@endif
<img src="{{ $user_avatar }}">
</button>
<button x-show="isOpen" @click="isOpen = false"
class="h-full w-full fixed inset-0 cursor-default"></button>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/front/category.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@forelse ($posts as $post)
<article class="flex flex-col shadow my-4">
<a href="{{ route('post.show', $post->slug) }}" class="hover:opacity-75">
<img src="{{ asset("storage/$post->image") }}" width="1000" height="500">
<img src="{{ $post->image }}" width="1000" height="500">
</a>
<div class="bg-white flex flex-col justify-start p-6">
<a href="{{ route('category.show', $post->category->slug) }} "
Expand Down
2 changes: 1 addition & 1 deletion resources/views/front/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@forelse ($posts as $post)
<article class="flex flex-col shadow my-4">
<a href="{{ route('post.show', $post->slug ) }}" class="hover:opacity-75">
<img src="{{ asset("storage/$post->image") }}" width="1000" height="500">
<img src="{{ $post->image }}" width="1000" height="500">
</a>
<div class="bg-white flex flex-col justify-start p-6">
<a href="{{ route('category.show', $post->category->slug) }} " class="text-blue-700 text-sm font-bold uppercase pb-4">{{ $post->category->name }}</a>
Expand Down
9 changes: 2 additions & 7 deletions resources/views/front/post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<article class="flex flex-col shadow my-4">
<!-- Article Image -->
<img src="{{ asset("storage/$post->image") }}" width="1000" height="500">
<img src="{{ $post->image }}" width="1000" height="500">
<div class="bg-white flex flex-col justify-start p-6">
<a href="{{ route('category.show', $post->category->slug) }}"
class="text-blue-700 text-sm font-bold uppercase pb-4">{{ $post->category->name }}</a>
Expand All @@ -23,13 +23,8 @@ class="text-blue-700 text-sm font-bold uppercase pb-4">{{ $post->category->name
{{-- author --}}
<div class="w-full flex flex-col text-center md:text-left md:flex-row shadow bg-white mt-10 mb-10 p-6">
<div class="w-full md:w-1/5 flex justify-center md:justify-start pb-4">
@if ($post->user->avatar == null)
<img src="{{ asset('import/assets/profile-pic-dummy.png') }}"
<img src="{{ $post->user->avatar }}"
class="rounded-full shadow h-32 w-32">
@else
<img src="{{ asset('storage') . '/' . $post->user->avatar }}"
class="rounded-full shadow h-32 w-32">
@endif
</div>
<div class="flex-1 flex flex-col justify-center md:justify-start">
<p class="font-semibold text-2xl">{{ $post->user->name }}</p>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/front/tag.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@forelse ($tags as $post)
<article class="flex flex-col shadow my-4">
<a href="{{ route('post.show', $post->slug ) }}" class="hover:opacity-75">
<img src="{{ asset("storage/$post->image") }}" width="1000" height="500">
<img src="{{ $post->image }}" width="1000" height="500">
</a>
<div class="bg-white flex flex-col justify-start p-6">
<a href="{{ route('category.show', $post->category->slug) }} "
Expand Down
7 changes: 1 addition & 6 deletions resources/views/layouts/blog.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,8 @@ class="flex justify-center items-center m-1 font-medium py-1 px-2 bg-white round
</div>
@forelse ($top_users as $top)
<div class="my-1.5 py-3 px-4 flex justify-center rounded-lg shadow-lg bg-white w-full ">
@if ($top->avatar == null)
<img src="{{ asset('import/assets/profile-pic-dummy.png') }}"
class="w-10 h-10 rounded-full">
@else
<img class="w-10 h-10 rounded-full" src="{{ asset("storage/$top->avatar") }}"
<img class="w-10 h-10 rounded-full" src="{{ $top->avatar }}"
alt="">
@endif
<div class="content flex justify-between py-2 w-full">
<div class="px-2 justify-between">
{{ $top->name }}
Expand Down

0 comments on commit ae84026

Please sign in to comment.