first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
<?php
namespace Modules\Content\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\Content\Interfaces\ContentCategoryInterface;
use Modules\Content\Models\ContentCategory;
use Yajra\DataTables\Facades\DataTables;
class ContentCategoryController extends Controller
{
/**
* Display a listing of the resource.
*/
protected $contentCategory;
public function __construct(ContentCategoryInterface $contentCategory)
{
$this->contentCategory = $contentCategory;
}
public function index(Request $request)
{
$data['title'] = 'Content Category List';
if ($request->ajax()) {
$model = ContentCategory::query();
return DataTables::eloquent($model)
// ->setRowId('{{$id}}')
->addIndexColumn()
->editColumn('desc', function ($row) {
return \Str::limit($row->desc, 20);
})
->addColumn('action', 'content::content-category.datatables.action-btn')
->addColumn('status', '{!! $status_name !!}')
->rawColumns(['action', 'status', 'desc'])
->toJson();
}
return view('content::content-category.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Content Category';
$data['status'] = ContentCategory::STATUS;
$data['editable'] = false;
return view('content::content-category.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$this->contentCategory->create($request->all());
return redirect()->route('contentCategory.index')->with('success', 'Content Category has been created!');
}
/**
* Show the specified resource.
*/
public function show($id)
{
try {
$data['title'] = 'Show Content Category';
$data['contentCategory'] = $this->contentCategory->getContentCategoryById($id);
return response()->json([
'status' => true,
'view' => view('content::content-category.show', $data)->render(),
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
], 500);
}
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Content Category';
$data['editable'] = true;
$data['status'] = ContentCategory::STATUS;
$data['contentCategory'] = $this->contentCategory->getContentCategoryById($id);
return response()->json([
'status' => true,
'view' => view('content::content-category.edit', $data)->render(),
'msg' => 'Fetch successfully',
], 200);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->contentCategory->update($id, $inputData);
return redirect()->route('contentCategory.index')->with('success', 'Content Category has been updated!');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$Model = $this->contentCategory->getContentCategoryById($id);
$Model->delete();
flash()->success('Content Category deleted succesfully');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Content Category deleted succesfully']);
}
}

View File

@@ -0,0 +1,427 @@
<?php
namespace Modules\Content\Http\Controllers;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Modules\Content\Interfaces\ContentCategoryInterface;
use Modules\Content\Interfaces\ContentInterface;
use Modules\Content\Models\Content;
use Modules\Employee\Models\Employee;
use Modules\Product\Interfaces\ProductInterface;
use Modules\User\Services\UserService;
use Yajra\DataTables\Facades\DataTables;
class ContentController extends Controller
{
private $content;
private $product;
private $category;
private $user;
public function __construct(
ContentInterface $content,
ProductInterface $product,
ContentCategoryInterface $category,
UserService $user
) {
$this->content = $content;
$this->product = $product;
$this->category = $category;
$this->user = $user;
}
public function index(Request $request)
{
$data['title'] = 'Schedule Content List';
$data['status'] = Content::STATUS;
$data['products'] = $this->product->getProductList();
$data['categories'] = $this->category->getContentCategoryList();
if ($request->ajax()) {
$model = Content::query();
$model->latest();
if ($request->has('filters')) {
$filters = $request->get('filters');
$this->applyFilters($model, $filters);
}
return DataTables::eloquent($model)
->addIndexColumn()
// ->setRowClass('{{"align-middle"}}')
->addColumn('product', function (Content $content) {
$productName = $content->product?->name ?? 'N/A';
$clientName = $content->product?->client?->name ?? 'N/A';
$html = '<div class="d-flex align-items-center"><div class="flex-shrink-0">';
$html .= '<h5 class="fs-14 mb-0">' . $productName . '</h5>';
$html .= '<p class="fs-12 mb-0 text-primary"><em> ' . $clientName . '</em></p>';
$html .= '</div></div>';
return $html;
})
->addColumn('createdby', function (Content $content) {
$createdByName = $content->createdBy?->name ?? 'Unknown';
$createdAt = $content->created_at?->format('d M, Y | H:i:s') ?? '-';
$html = '<div class="d-flex align-items-center"><div class="flex-shrink-0">';
$html .= '<h5 class="fs-14 mb-0">' . $createdByName . '</h5>';
$html .= '<p class="fs-12 mb-0 text-muted"><em> ' . $createdAt . '</em></p>';
$html .= '</div></div>';
return $html;
})
->addColumn('category', function (Content $content) {
return $content->category?->title;
})
->addColumn('status', '{!! $status_name !!}')
->addColumn('action', 'content::content.datatables.action-btn')
->rawColumns(['action', 'status', 'product', 'createdby'])
->toJson();
}
return view('content::content.all', $data);
}
public function draft(Request $request)
{
$data['title'] = 'Content List';
$data['status'] = Content::STATUS;
$data['products'] = $this->product->getProductList();
$data['categories'] = $this->category->getContentCategoryList();
if ($request->ajax()) {
$model = Content::query();
$model->where('status', 11)->latest();
if ($request->has('filters')) {
$filters = $request->get('filters');
$this->applyFilters($model, $filters);
}
return DataTables::eloquent($model)
->addIndexColumn()
->addColumn('title', function(Content $content){
return '<a target="_blank" href="'. route('content.show', $content->id) .'">'. $content->title .'</a>';
})
->addColumn('product', function (Content $content) {
$html = '<div class="d-flex align-items-center"><div class="flex-shrink-0"><h5 class="fs-14 mb-0">' . $content->product?->name . '</h5>';
$html .= '<p class="fs-12 mb-0 text-primary"><em> ' . @$content->product?->client->name . '</em></p>';
$html .= '</div></div>';
return $html;
})
->addColumn('createdby', function (Content $content) {
$createdByName = $content->createdBy ? $content->createdBy->name : 'N/A';
$createdAt = $content->created_at ? $content->created_at->format('d M, Y | H:i:s') : 'N/A';
$html = '<div class="d-flex align-items-center"><div class="flex-shrink-0"><h5 class="fs-14 mb-0">' . $createdByName . '</h5>';
$html .= '<p class="fs-12 mb-0 text-danger"><em> ' . $createdAt . '</em></p>';
$html .= '</div></div>';
return $html;
})
->addColumn('category', function (Content $content) {
return $content->category?->title;
})
->addColumn('status', '{!! $status_name !!}')
->addColumn('action', 'content::content.datatables.action-btn')
->rawColumns(['action', 'title', 'product', 'status', 'createdby'])
->toJson();
}
return view('content::content.index', $data);
}
protected function applyFilters($query, $filters)
{
// Global Search
if (!empty($filters['search'])) {
$query->where(function ($q) use ($filters) {
$q->where('title', 'like', '%' . $filters['search'] . '%');
// $q->orWhere('email', 'like', '%' . $filters['search'] . '%'); // Uncomment if needed
});
}
// Date Filter
if (!empty($filters['date'])) {
$dateFilter = explode("to", $filters['date']);
$startDate = trim($dateFilter[0]);
$endDate = trim($dateFilter[1]);
if ($startDate === $endDate) {
$query->where('created_at', '>=', $startDate);
} else {
$query->whereBetween('created_at', [$startDate, $endDate]);
}
}
// Product Filter
if (!empty($filters['product_id'])) {
$query->where('product_id', $filters['product_id']);
}
// Category Filter
if (!empty($filters['category_id'])) {
$query->where('category_id', $filters['category_id']);
}
// Status Filter
if (!empty($filters['status'])) {
$query->where('status', $filters['status']);
}
return $query;
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Content';
$data['editable'] = false;
$data['status'] = Content::STATUS;
$data['products'] = $this->product->getProductList();
$data['categories'] = $this->category->getContentCategoryList();
return view('content::content.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$inputData = $request->all();
$ClientLog = $this->product->getProductById($inputData['product_id'])->client;
$validator = Validator::make($request->all(), [
]);
if ($validator->fails()) {
return to_route('content.create')->withError($validator->errors()->all());
}
try {
if ($request->hasFile('creative')) {
$inputData['creative'] = uploadImage($request->creative);
}
$this->content->create($inputData);
$ClientLog->createLog([
'title' => 'Content Created',
'data' => "A new content titled '{$request->title}' has been created with the status: '" . (Content::STATUS[$request->status] ?? 'Unknown') . "'.",
]);
$employeId = auth()->user()->employee_id;
if ($employeId) {
Employee::findOrFail($employeId)->createLog([
'title' => 'Content Created',
'data' => "A new content titled '{$request->title}' has been created with the status: '" . (Content::STATUS[$request->status] ?? 'Unknown') . "'.",
]);
}
// $userList = $this->user->getAllUsersNoticeByEmployee();
// sendNotification($userList, [
// 'msg' => 'New Notice for Employee',
// ]);
return redirect()->route('content.index')->with('success', 'Content has been created!');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Content Schedule';
$content = $data['content'] = $this->content->getContentById($id);
$data['statusList'] = Content::STATUS;
if ($content->release_date) {
$releasedDateTime = Carbon::createFromFormat('Y-m-d H:i:s', $content->getRawOriginal('release_date') . ' ' . $content->getRawOriginal('release_time'));
$now = Carbon::now();
if ($releasedDateTime->isFuture()) {
$data['formatedTime'] = $releasedDateTime->diffForHumans($now, [
'parts' => 3,
'join' => true,
]);
$data['class'] = 'text-success';
} else {
$data['formatedTime'] = $releasedDateTime->diffForHumans($now, [
'parts' => 3,
'join' => true,
]);
$data['class'] = 'text-danger';
}
}
return view('content::content.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Content';
$data['content'] = $this->content->getContentById($id);
$data['editable'] = true;
$data['status'] = Content::STATUS;
$data['products'] = $this->product->getProductList();
$data['categories'] = $this->category->getContentCategoryList();
return view('content::content.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$clientLog = $this->product->getProductById($inputData['product_id'])->client;
$title = $inputData['title'];
try {
if ($request->hasFile('creative')) {
$inputData['creative'] = uploadImage($request->creative);
// Add log for file upload
$clientLog->createLog([
'title' => 'Content Updated with Document',
'data' => "The content titled '{$title}' has been updated with a new document and the status: '" . (Content::STATUS[$request->status] ?? 'Unknown') . "'.",
]);
}
$this->content->update($id, $inputData);
$clientLog->createLog([
'title' => 'Content Updated',
'data' => "A new content titled '{$request->title}' has been created with the status: '"
. (Content::STATUS[$request->status] ?? 'Unknown') . "'.",
]);
$employeId = auth()->user()->employee_id;
if ($employeId) {
Employee::findOrFail($employeId)->createLog([
'title' => 'Content Updated',
'data' => "A new content titled '{$request->title}' has been created with the status: '"
. (Content::STATUS[$request->status] ?? 'Unknown') . "'.",
]);
}
return redirect()->route('content.index')->with('success', 'Content has been updated!');
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$content = $this->content->getContentById($id);
$clientLog = $content->product->client;
$clientLog->createLog([
'title' => 'Content Deleted',
'data' => "The content titled '{$content->title}' has been deleted.",
]);
$content->delete();
return response()->json(['status' => true, 'message' => 'Content deleted succesfully']);
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
public function schedule()
{
try {
$content = $this->content->getContentById(request()->id);
$statusValue = Content::STATUS[request()->status];
$content->update([
'status' => request()->status,
'release_date' => request()->release_date,
'release_time' => request()->release_time,
'remarks' => request()->remarks,
]);
// Log for the client and employee
$releaseDateTime = Carbon::parse(request()->release_date . ' ' . request()->release_time)->format('l, F j, Y \a\t g:i A');
$content->product->client->createLog([
'title' => 'Content Scheduled',
'data' => "Content titled '{$content->title}' has been scheduled for release on {$releaseDateTime}. Status updated to '$statusValue'.",
]);
$employeeId = auth()->user()->employee_id;
if ($employeeId) {
Employee::findOrFail($employeeId)->createLog([
'title' => 'Content Scheduled',
'data' => "You scheduled the content titled '{$content->title}' for release on {$releaseDateTime}. Status updated to '$statusValue'.",
]);
}
flash()->addSuccess("Content has been " . lcfirst($statusValue) . ".");
return redirect()->back();
} catch (\Throwable $th) {
flash()->addError('Something went Wrong, Please try again!');
return redirect()->back()->withError($th->getMessage());
}
}
public function updateStatus()
{
try {
$content = $this->content->getContentById(request()->id);
$previousStatus = Content::STATUS[$content->status];
$currentStatus = Content::STATUS[request()->status];
$content->update([
'status' => request()->status,
]);
$content->product->client->createLog([
'title' => 'Content Status Changed',
'data' => "Content status Changed from '$previousStatus' to '$currentStatus'.",
]);
$employeId = auth()->user()->employee_id;
if ($employeId) {
Employee::findOrFail($employeId)->createLog([
'title' => 'Content Created',
'data' => "Content status Changed from '$previousStatus' to '$currentStatus'.",
]);
}
return response()->json([
'status' => true,
'msg' => "Content status has been successfully updated to '" . lcfirst($currentStatus) . "'.",
]);
} catch (\Throwable $th) {
return redirect()->back()->withError($th->getMessage());
}
}
public function getContentModal($id)
{
$data['content'] = $this->content->getContentById($id);
return view('content::content.partials._edit-modal', $data);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Content\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContentCategoryRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
//
];
}
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Content\Interfaces;
interface ContentCategoryInterface
{
public function findAll();
public function getContentCategoryById($ContentCategoryId);
public function getContentCategoryList();
public function create(array $ContentCategoryDetails);
public function update($ContentCategoryId, array $newDetails);
public function delete($ContentCategoryId);
public function pluck();
public function count();
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Modules\Content\Interfaces;
interface ContentInterface
{
public function findAll();
public function findAllUpcomingScheduledContent();
public function getContentById($ContentId);
public function getContentByEmail($email);
public function delete($ContentId);
public function create($ContentDetails);
public function update($ContentId, array $newDetails);
public function pluck();
public function count();
}

View File

@@ -0,0 +1,90 @@
<?php
namespace Modules\Content\Models;
use App\Traits\CreatedUpdatedBy;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Modules\Admin\Models\ActivityLog;
use Modules\Product\Models\Product;
class Content extends Model
{
use HasFactory, CreatedUpdatedBy;
const STATUS = [
11 => 'Draft',
12 => 'Scheduled',
13 => 'Published',
14 => 'Archived',
];
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'title',
'product_id',
'category_id',
'release_date',
'release_time',
'creative',
'caption',
'desc',
'order',
'createdby',
'updatedby',
'status',
'remarks',
];
protected $appends = ['status_name'];
protected $casts = [
'release_date' => 'date:Y-m-d',
'release_time' => 'datetime:H:i:s',
];
protected function statusName(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
switch ($attributes['status']) {
case '11':
return '<span class="badge bg-dark">' . self::STATUS[$attributes['status']] . '</span>';
case '12':
return '<span class="badge bg-success">' . self::STATUS[$attributes['status']] . '</span>';
case '13':
return '<span class="badge bg-primary">' . self::STATUS[$attributes['status']] . '</span>';
case '14':
return '<span class="badge bg-danger">' . self::STATUS[$attributes['status']] . '</span>';
default:
# code...
break;
}
},
set: fn($value) => $value,
);
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
public function category()
{
return $this->belongsTo(ContentCategory::class, 'category_id');
}
public function activityLogs(): MorphMany
{
return $this->morphMany(ActivityLog::class, 'loggable')->latest();
}
public function createLog($data)
{
return $this->activityLogs()->create($data);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\Content\Models;
use App\Traits\StatusTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ContentCategory extends Model
{
use HasFactory, StatusTrait;
protected $fillable = [
'title',
'desc',
'order',
'status',
];
protected $appends = ['status_name'];
}

View File

View File

@@ -0,0 +1,126 @@
<?php
namespace Modules\Content\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Content\Interfaces\ContentCategoryInterface;
use Modules\Content\Interfaces\ContentInterface;
use Modules\Content\Repositories\ContentCategoryRepository;
use Modules\Content\Repositories\ContentRepository;
class ContentServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Content';
protected string $moduleNameLower = 'content';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->bind(ContentInterface::class, ContentRepository::class);
$this->app->bind(ContentCategoryInterface::class, ContentCategoryRepository::class);
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower . '.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace') . '\\' . $this->moduleName . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
/**
* Get the services provided by the provider.
*
* @return array<string>
*/
public function provides(): array
{
return [];
}
/**
* @return array<string>
*/
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
$paths[] = $path . '/modules/' . $this->moduleNameLower;
}
}
return $paths;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Content\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*
* @return void
*/
protected function configureEmailVerification(): void
{
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Content\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path('Content', '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Content', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Modules\Content\Repositories;
use Modules\Content\Interfaces\ContentCategoryInterface;
use Modules\Content\Models\ContentCategory;
class ContentCategoryRepository implements ContentCategoryInterface
{
public function findAll()
{
return ContentCategory::when(true, function ($query) {
})->latest()->paginate(20);
}
public function getContentCategoryById($ContentCategoryId)
{
return ContentCategory::findOrFail($ContentCategoryId);
}
public function getContentCategoryList()
{
return ContentCategory::pluck('title', 'id');
}
public function delete($ContentCategoryId)
{
ContentCategory::destroy($ContentCategoryId);
}
public function create($ContentCategoryDetails)
{
return ContentCategory::create($ContentCategoryDetails);
}
public function update($ContentCategoryId, array $newDetails)
{
return ContentCategory::whereId($ContentCategoryId)->update($newDetails);
}
public function pluck(){
return ContentCategory::pluck('title', 'id');
}
public function count(){
return ContentCategory::count();
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Modules\Content\Repositories;
use Modules\Content\Interfaces\ContentInterface;
use Modules\Content\Models\Content;
class ContentRepository implements ContentInterface
{
public function findAll()
{
return Content::all();
}
public function findAllUpcomingScheduledContent()
{
return Content::when(true, function($query){
if (auth()->user()->hasRole('employee')) {
$query->where("createdby", auth()->user()->id);
}
})
->where('status', 12)
->whereDate('release_date', '>=', now())
->get();
}
public function getContentById($ContentId)
{
return Content::findOrFail($ContentId);
}
public function getContentByEmail($email)
{
return Content::where('email', $email)->first();
}
public function delete($ContentId)
{
Content::destroy($ContentId);
}
public function create($ContentDetails)
{
return Content::create($ContentDetails);
}
public function update($ContentId, array $newDetails)
{
return Content::whereId($ContentId)->update($newDetails);
}
public function pluck()
{
return Content::pluck('title', 'id');
}
public function count()
{
return Content::count();
}
}