first change
This commit is contained in:
68
Modules/Sitemap/app/Repositories/SitemapConfigRepository.php
Normal file
68
Modules/Sitemap/app/Repositories/SitemapConfigRepository.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sitemap\Repositories;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Sitemap\Interfaces\SitemapConfigInterface;
|
||||
use Modules\Sitemap\Models\SitemapConfig;
|
||||
|
||||
class SitemapConfigRepository implements SitemapConfigInterface
|
||||
{
|
||||
public function findAll(?Request $request = null, ?callable $query = null, bool $paginate = false, ?int $limit = 10)
|
||||
{
|
||||
$baseQuery = SitemapConfig::query();
|
||||
|
||||
if ($query) {
|
||||
$query($baseQuery);
|
||||
}
|
||||
|
||||
if ($paginate) {
|
||||
return $baseQuery->paginate($limit);
|
||||
}
|
||||
|
||||
return $baseQuery->latest()->get();
|
||||
}
|
||||
|
||||
|
||||
public function findById(int $id, ?callable $query = null)
|
||||
{
|
||||
$baseQuery = SitemapConfig::query();
|
||||
|
||||
if (is_callable($query)) {
|
||||
$query($baseQuery);
|
||||
}
|
||||
|
||||
return $baseQuery->whereId($id)->firstOrFail();
|
||||
}
|
||||
|
||||
public function delete(int $id)
|
||||
{
|
||||
$sitemapConfig = $this->findById($id);
|
||||
$sitemapConfig->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
return SitemapConfig::create($data);
|
||||
}
|
||||
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
return tap($this->findById($id), function ($sitemapConfig) use ($data) {
|
||||
$sitemapConfig->update($data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function pluck(string $column, string $key, ?callable $query = null)
|
||||
{
|
||||
$baseQuery = SitemapConfig::query();
|
||||
|
||||
if (is_callable($query)) {
|
||||
$query($baseQuery);
|
||||
}
|
||||
|
||||
return $baseQuery->pluck($key, $column);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user