Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mcoil.corals.io/app/Shop/Blogs/Repositories/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mcoil.corals.io/app/Shop/Blogs/Repositories/BlogRepository.php
<?php

namespace App\Shop\Blogs\Repositories;

use App\Shop\Blogs\Blog;
use Illuminate\Support\Collection;
use Jsdecena\Baserepo\BaseRepository;
use Illuminate\Database\QueryException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Shop\Blogs\Repositories\Interfaces\BlogRepositoryInterface;
use App\Shop\Tools\UploadableTrait;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

class BlogRepository extends BaseRepository implements BlogRepositoryInterface
{
	/**
     * BlogRepository constructor.
     * 
     * @param Blog $dummy
     */
    public function __construct(Blog $dummy)
    {
        parent::__construct($dummy);
        $this->model = $dummy;
    }

    /**
     * List all the Blogs
     *
     * @param string $order
     * @param string $sort
     * @param array $except
     * @return \Illuminate\Support\Collection
     */
    public function listBlogs(string $order = 'id', string $sort = 'desc', $except = []) : Collection
    {
        return $this->model->orderBy($order, $sort)->get()->except($except);
    }

    /**
     * Create Blog
     *
     * @param array $params
     *
     * @return Blog
     * @throws InvalidArgumentException
     */
    public function createBlog(array $params) : Blog
    {
        try {
        	return Blog::create($params);
        } catch (QueryException $e) {
            throw new InvalidArgumentException($e->getMessage());
        }
    }

    /**
     * Update the dummy
     *
     * @param array $params
     * @return Blog
     */
    public function updateBlog(array $params) : Blog
    {
        $dummy = $this->findBlogById($this->model->id);
        $dummy->update($params);
        return $dummy;
    }

    /**
     * @param int $id
     * 
     * @return Blog
     * @throws ModelNotFoundException
     */
    public function findBlogById(int $id) : Blog
    {
        try {
            return $this->findOneOrFail($id);
        } catch (ModelNotFoundException $e) {
            throw new ModelNotFoundException($e->getMessage());
        }
    }

    /**
     * Delete a dummy
     *
     * @return bool
     */
    public function deleteBlog() : bool
    {
        return $this->model->delete();
    }

    /**
     * @param UploadedFile $file
     * @return string
     */
    public function saveImage(UploadedFile $file) : string
    {
        $filename     = $file->getClientOriginalName();
        Storage::disk('images_uploaded') -> put($filename, file_get_contents($file -> getRealPath())); 
        return $filename;

        // return $file->store('blog_images', ['disk' => 'public']); 

    }

    /**
     * @param string $field
     * Delete file
     * @return bool
     */
    public function deleteImage($field='imageOne') : bool
    {
        return \Storage::disk('public')->delete($this->model->getOriginal()[$field]);
    }
     
}

Spamworldpro Mini