Al-HUWAITI Shell
Al-huwaiti


Server : LiteSpeed
System : Linux server335.web-hosting.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : cardxfeb ( 2452)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/cardxfeb/www/app/Repositories/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/cardxfeb/www/app/Repositories/BlogRepository.php
<?php

namespace App\Repositories;

use App\Models\Blog;
use DB;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Yajra\DataTables\Exceptions\Exception;

class BlogRepository extends BaseRepository
{
    /**
     * @var array
     */
    public $fieldSearchable = [
        'title',
    ];

    /**
     * {@inheritDoc}
     */
    public function getFieldsSearchable()
    {
        return $this->fieldSearchable;
    }

    /**
     * {@inheritDoc}
     */
    public function model()
    {
        return Blog::class;
    }

    /**
     * @return mixed
     */
    public function store($input)
    {

        try {
            DB::beginTransaction();
            $blog = Blog::create($input);

            if (isset($input['blog_image']) && !empty($input['blog_image'])) {
                $blog->addMedia($input['blog_image'])->toMediaCollection(Blog::BLOGIMAGE, config('app.media_disc'));
            }

            DB::commit();

            return $blog;
        } catch (Exception $e) {
            DB::rollBack();

            throw new UnprocessableEntityHttpException($e->getMessage());
        }
    }

    public function update($input, $id)
    {
        try {
            DB::beginTransaction();
            $blog = Blog::findOrFail($id);
            $blog->update($input);
            if (isset($input['blog_image']) && !empty($input['blog_image'])) {
                $blog->clearMediaCollection(Blog::BLOGIMAGE);
                $blog->addMedia($input['blog_image'])->toMediaCollection(Blog::BLOGIMAGE, config('app.media_disc'));
            }
            DB::commit();
            return $blog;
        } catch (Exception $e) {
            DB::rollBack();
            throw new UnprocessableEntityHttpException($e->getMessage());
        }
    }
}

Al-HUWAITI Shell