comments
This commit is contained in:
@@ -2,23 +2,50 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use BeyondCode\Comments\Comment;
|
||||
use App\Models\Core\Comment as rawComment;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
|
||||
use App\Datatables\Admin\Core\CommentsDataTable;
|
||||
|
||||
class Comments
|
||||
{
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return rawComment::find($id);
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = new CommentsDataTable();
|
||||
return $model->html();
|
||||
}
|
||||
|
||||
public static function getCommentsByClass($class, $id)
|
||||
{
|
||||
return self::getByModel(self::getModel($class, $id));
|
||||
}
|
||||
|
||||
public static function getModel($class, $id)
|
||||
{
|
||||
return $$class::find($id);
|
||||
}
|
||||
|
||||
public static function getClass($class)
|
||||
{
|
||||
return 'App\Models\\' . str_replace('.','\\', $class);
|
||||
}
|
||||
|
||||
public static function getByModel($model)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
return $model->comments;
|
||||
return $model ? $model->comments : false;
|
||||
}
|
||||
|
||||
public static function storeComments($model, $comments)
|
||||
{
|
||||
if ($comments) {
|
||||
foreach ($comments as $comment) {
|
||||
self::storeComment($model, $comment);
|
||||
}
|
||||
foreach (($comments ?? []) as $comment) {
|
||||
self::storeComment($model, $comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +54,31 @@ class Comments
|
||||
return $model->comment($comment);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
unset($data['_token']);
|
||||
$data['commentable_type'] = Comments::getClass($data['commentable_type']);
|
||||
$data['commentable_id'] = (int) $data['commentable_id'];
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
unset($data['id']);
|
||||
$data['is_approved'] = true;
|
||||
$data['user_id'] = Users::getId();
|
||||
return rawComment::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$model = self::get($id);
|
||||
$model->update($data);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function deleteComments($model)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Support\Str;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Media;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Models\Shop\Article;
|
||||
@@ -37,6 +38,10 @@ class Articles
|
||||
$data['article']['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['article']['tags'] = self::getTagsByArticle($article);
|
||||
// $data['article']['prices'] = self::getPricesByArticle($article);
|
||||
|
||||
// $data['datatables']['comments'] = Comments::getDatatable();
|
||||
$data['article']['comments'] = $article->comments;
|
||||
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
53
app/Repositories/Shop/Offers.php
Normal file
53
app/Repositories/Shop/Offers.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
|
||||
class Offers
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Offer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Offer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Offer::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Offer::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Offer::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Offer::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class Tariffs
|
||||
{
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Tariff::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$data = Tariff::where('name', 'LIKE', "%${str}%")->orWhere('ref', 'LIKE', "${str}%")->orWhere('code', 'LIKE', "${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
|
||||
Reference in New Issue
Block a user