151 lines
4.2 KiB
PHP
151 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sitemap\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Modules\Sitemap\Interfaces\SitemapConfigInterface;
|
|
use Modules\Sitemap\Models\SitemapConfig;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class SitemapConfigController extends Controller
|
|
{
|
|
|
|
public function __construct(private SitemapConfigInterface $sitemapConfig)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$isEditing = $request->has("id");
|
|
|
|
$sitemapConfig = $isEditing ? $this->sitemapConfig->findById($request->id) : null;
|
|
|
|
if (request()->ajax()) {
|
|
|
|
$model = SitemapConfig::query()->latest();
|
|
|
|
return DataTables::eloquent($model)
|
|
->addIndexColumn()
|
|
->setRowClass('tableRow')
|
|
->editColumn('status', function (SitemapConfig $sitemapConfig) {
|
|
$status = $sitemapConfig->status ? 'Published' : 'Draft';
|
|
$color = $sitemapConfig->status ? 'text-success' : 'text-danger';
|
|
return "<p class='{$color}'>{$status}</p>";
|
|
})
|
|
->addColumn('action', 'sitemap::sitemapConfig.datatable.action')
|
|
->rawColumns(['action', 'status'])
|
|
->toJson();
|
|
}
|
|
|
|
return view('sitemap::sitemapConfig.index', [
|
|
'sitemapConfig' => $sitemapConfig,
|
|
'title' => $isEditing ? 'Edit Sitemap Config' : 'Add Sitemap Config',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$isEditing = $request->has('id');
|
|
|
|
if ($isEditing) {
|
|
$validated = $request->validate([
|
|
'title' => ['required', 'string', 'max:255', 'unique:sitemap_configs,title,' . $request->id],
|
|
'max_depth' => ['nullable', 'integer'],
|
|
'max_crawl_count' => ['nullable', 'integer'],
|
|
'sitemap_excludes' => ['nullable', 'string'],
|
|
"ignore_robot" => ['required', 'boolean'],
|
|
]);
|
|
|
|
$sitemapConfig = $this->sitemapConfig->update($request->id, $validated);
|
|
session()->flash("success", "Sitemap Config successfully updated.");
|
|
return to_route('sitemapConfig.index');
|
|
}
|
|
|
|
$maxOrder = SitemapConfig::max('order');
|
|
$order = $maxOrder ? ++$maxOrder : 1;
|
|
|
|
$request->mergeIfMissing([
|
|
'order' => $order
|
|
]);
|
|
|
|
$validated = $request->validate([
|
|
'title' => ['required', 'string', 'unique:sitemap_configs,title'],
|
|
'max_depth' => ['nullable', 'integer'],
|
|
'max_crawl_count' => ['nullable', 'integer'],
|
|
'sitemap_excludes' => ['nullable', 'string'],
|
|
"ignore_robot" => ['required', 'boolean'],
|
|
'order' => ['integer'],
|
|
]);
|
|
|
|
$sitemapConfig = $this->sitemapConfig->create($validated);
|
|
session()->flash("success", "Sitemap Config successfully created.");
|
|
|
|
return to_route('sitemapConfig.index');
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$sitemapConfig = $this->sitemapConfig->delete($id);
|
|
return response()->json([
|
|
'status' => 200,
|
|
'message' => "Sitemap Config successfully deleted."
|
|
], 200);
|
|
}
|
|
|
|
public function toggle($id)
|
|
{
|
|
$sitemapConfig = $this->sitemapConfig->findById($id);
|
|
|
|
$sitemapConfig->update([
|
|
'status' => !$sitemapConfig->status
|
|
]);
|
|
return response([
|
|
'status' => 200,
|
|
'message' => 'Sitemap Config successfully toggled.'
|
|
], 200);
|
|
}
|
|
}
|