diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php index 40c381d..a4f0f93 100755 --- a/app/Http/Controllers/PostController.php +++ b/app/Http/Controllers/PostController.php @@ -62,7 +62,17 @@ public function __construct(Request $request, PostRepository $repo, ActivityLogR $this->activity = $activity; $this->user = $user; $this->category = $category; - $this->middleware('permission:access-post'); + $this->middleware('permission:access-post')->except(['index']); + } + + /** + * Display all posts + * + * @return Post[]|Collection + */ + public function index() + { + return $this->repo->getPosts($this->request->all()); } /** @@ -200,9 +210,7 @@ public function uploadCover($id) $filename = uniqid(); request()->file('image')->move($image_path, $filename . "." . $extension); $img = \Image::make($image_path . $filename . "." . $extension); - $img->resize(500, null, function ($constraint) { - $constraint->aspectRatio(); - }); + $img->resize(600, 300); $img->save($image_path . $filename . "." . $extension); $post->cover = $image_path . $filename . "." . $extension; $post->save(); diff --git a/app/Post.php b/app/Post.php index 2357d01..b9295e8 100755 --- a/app/Post.php +++ b/app/Post.php @@ -17,6 +17,7 @@ * @property string|null $cover * @property \Carbon\Carbon|null $created_at * @property \Carbon\Carbon|null $updated_at + * @property-read string|null $stripped_body * @property-read \App\User $user * @property-read \App\Category $category */ @@ -34,6 +35,13 @@ class Post extends Model 'body' ]; + /** + * The accessors to append to the model's array form. + * + * @var array + */ + protected $appends = ['stripped_body']; + /** * Get the user that owns the post. * @@ -74,6 +82,26 @@ public function getUpdatedAtAttribute() return Carbon::parse($this->attributes['updated_at'])->diffForHumans(); } + /** + * Get body with the stripped HTML tags. + * + * @return string + */ + public function getStrippedBodyAttribute() + { + return strip_tags($this->attributes['body']); + } + + /** + * Get cover image. + * + * @return string + */ + public function getCoverAttribute() + { + return $this->attributes['cover'] ?: 'uploads/images/cover-default.png'; + } + /** * Sets the title and the readable slug. * diff --git a/app/Repositories/PostRepository.php b/app/Repositories/PostRepository.php index 88c0e6e..d472396 100755 --- a/app/Repositories/PostRepository.php +++ b/app/Repositories/PostRepository.php @@ -24,6 +24,25 @@ public function __construct(Post $post) $this->post = $post; } + /** + * Get published posts. + * + * @param array $params + * + * @return Post[]|Collection + */ + public function getPosts($params = []) + { + $page_length = isset($params['page_length']) ? $params['page_length'] : config('config.page_length'); + $published = $this->post->with('user', 'user.profile', 'category')->filterByIsDraft(0); + + if (!isset($params['page_length'])) { + return $published->get(); + } + + return $published->orderBy('created_at', 'desc')->paginate($page_length); + } + /** * Get post query. * diff --git a/public/uploads/images/cover-default.jpg b/public/uploads/images/cover-default.jpg deleted file mode 100644 index 927874c..0000000 Binary files a/public/uploads/images/cover-default.jpg and /dev/null differ diff --git a/public/uploads/images/cover-default.png b/public/uploads/images/cover-default.png new file mode 100644 index 0000000..09a1f27 Binary files /dev/null and b/public/uploads/images/cover-default.png differ diff --git a/resources/assets/js/components/PaginationRecord.vue b/resources/assets/js/components/PaginationRecord.vue index c24080a..0c233cf 100755 --- a/resources/assets/js/components/PaginationRecord.vue +++ b/resources/assets/js/components/PaginationRecord.vue @@ -3,7 +3,7 @@
-
+