mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-01-16 19:05:08 -05:00
101 lines
2.4 KiB
PHP
101 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\StudioPlus\Repositories;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Modules\StudioPlus\Entities\UrlLabel;
|
|
|
|
class UrlLabelsRepository
|
|
{
|
|
public function getAll()
|
|
{
|
|
return UrlLabel::orderBy('label')->get();
|
|
}
|
|
|
|
public function store($request): array
|
|
{
|
|
$label = $request->label;
|
|
|
|
UrlLabel::create([
|
|
'label' => $label,
|
|
]);
|
|
|
|
$labels = UrlLabel::orderBy('label')->get();
|
|
|
|
return [
|
|
'data' => [
|
|
'message' => 'Url label has been saved.',
|
|
'labels' => $labels,
|
|
],
|
|
'status' => 200,
|
|
];
|
|
}
|
|
|
|
public function update($request): array
|
|
{
|
|
$id = $request->id;
|
|
$label = UrlLabel::find($id);
|
|
|
|
if ($label) {
|
|
$other_label = UrlLabel::where('label', $request->label)->where('id', '<>', $id)->first();
|
|
|
|
if ($other_label) {
|
|
return [
|
|
'data' => [
|
|
'message' => 'Label already exists.',
|
|
'category' => $other_label,
|
|
],
|
|
'status' => 409,
|
|
];
|
|
}
|
|
|
|
$label->fill($request->all());
|
|
$label->update();
|
|
$labels = UrlLabel::orderBy('label')->get();
|
|
|
|
return [
|
|
'data' => [
|
|
'message' => 'Label has been udpated.',
|
|
'labels' => $labels
|
|
],
|
|
'status' => 200,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'data' => [
|
|
'message' => 'Label not found.',
|
|
],
|
|
'status' => 404,
|
|
];
|
|
}
|
|
|
|
public function destroy($request): array
|
|
{
|
|
$label = UrlLabel::find($request->id);
|
|
|
|
if ($label) {
|
|
$label->delete();
|
|
$labels = UrlLabel::orderBy('label')->get();
|
|
|
|
return [
|
|
'data' => [
|
|
'message' => 'Label has been deleted.',
|
|
'labels' => $labels,
|
|
],
|
|
'status' => 200,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'data' => [
|
|
'message' => 'Label not found.',
|
|
],
|
|
'status' => 404,
|
|
];
|
|
}
|
|
}
|