Skip to content

Commit 55b49b3

Browse files
authored
Merge pull request #138 from bvipul/develop
Blog and Faq Tests
2 parents 28f4d36 + 7f0cd84 commit 55b49b3

File tree

12 files changed

+556
-133
lines changed

12 files changed

+556
-133
lines changed

app/Models/Blogs/Traits/Relationship/BlogRelationship.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function tags()
3030
/**
3131
* Blogs belongsTo with User.
3232
*/
33-
public function createdBy()
33+
public function owner()
3434
{
35-
return $this->belongsTo(User::class, 'created_by', 'id');
35+
return $this->belongsTo(User::class, 'created_by');
3636
}
3737
}

app/Repositories/Backend/Blogs/BlogsRepository.php

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
namespace App\Repositories\Backend\Blogs;
44

5-
use App\Events\Backend\Blogs\BlogCreated;
5+
use DB;
6+
use Carbon\Carbon;
7+
use App\Models\Blogs\Blog;
8+
use App\Models\BlogTags\BlogTag;
9+
use App\Http\Utilities\FileUploads;
10+
use App\Exceptions\GeneralException;
11+
use App\Repositories\BaseRepository;
12+
use App\Models\BlogMapTags\BlogMapTag;
13+
use Illuminate\Support\Facades\Storage;
614
use App\Events\Backend\Blogs\BlogDeleted;
715
use App\Events\Backend\Blogs\BlogUpdated;
8-
use App\Exceptions\GeneralException;
9-
use App\Http\Utilities\FileUploads;
16+
use App\Events\Backend\Blogs\BlogCreated;
1017
use App\Models\BlogCategories\BlogCategory;
1118
use App\Models\BlogMapCategories\BlogMapCategory;
12-
use App\Models\BlogMapTags\BlogMapTag;
13-
use App\Models\Blogs\Blog;
14-
use App\Models\BlogTags\BlogTag;
15-
use App\Repositories\BaseRepository;
16-
use Carbon\Carbon;
17-
use DB;
1819

1920
/**
2021
* Class BlogsRepository.
@@ -26,6 +27,21 @@ class BlogsRepository extends BaseRepository
2627
*/
2728
const MODEL = Blog::class;
2829

30+
protected $upload_path;
31+
32+
/**
33+
* Storage Class Object.
34+
*
35+
* @var \Illuminate\Support\Facades\Storage
36+
*/
37+
protected $storage;
38+
39+
public function __construct()
40+
{
41+
$this->upload_path = 'img' . DIRECTORY_SEPARATOR . 'blog' . DIRECTORY_SEPARATOR;
42+
$this->storage = Storage::disk('public');
43+
}
44+
2945
/**
3046
* @return mixed
3147
*/
@@ -210,13 +226,12 @@ public function delete(Blog $blog)
210226
*/
211227
public function uploadImage($input)
212228
{
213-
$uploadManager = new FileUploads();
214229
$avatar = $input['featured_image'];
215230

216231
if (isset($input['featured_image']) && !empty($input['featured_image'])) {
217-
$fileName = $uploadManager->setBasePath('backend/blog_images')
218-
->setThumbnailFlag(false)
219-
->upload($input['featured_image']);
232+
$fileName = time() . $avatar->getClientOriginalName();
233+
234+
$this->storage->put($this->upload_path . $fileName, file_get_contents($avatar->getRealPath()));
220235

221236
$input = array_merge($input, ['featured_image' => $fileName]);
222237

@@ -231,11 +246,8 @@ public function uploadImage($input)
231246
*/
232247
public function deleteOldFile($model)
233248
{
234-
$uploadManager = new FileUploads();
235249
$fileName = $model->featured_image;
236-
$filePath = $uploadManager->setBasePath('backend/blog_images');
237-
$file = $filePath->filePath.DIRECTORY_SEPARATOR.$fileName;
238-
239-
return $uploadManager->deleteFile($file);
250+
251+
return $this->storage->delete($this->upload_path . $fileName);
240252
}
241253
}

0 commit comments

Comments
 (0)