2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Labels;
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-05 16:58:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-03-05 16:02:12 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class LabelsController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$labels = Labels::all();
|
|
|
|
return view('labels.index', compact(['labels']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('labels.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2022-10-20 02:06:44 +02:00
|
|
|
'label' => 'required|string|min:2'
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
Labels::create([
|
|
|
|
'id' => Str::random(8),
|
|
|
|
'label' => $request->label
|
|
|
|
]);
|
|
|
|
|
2022-03-05 16:58:25 +01:00
|
|
|
Cache::forget('all_labels');
|
2022-05-14 16:15:20 +02:00
|
|
|
Cache::forget('labels_count');
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('labels.index')
|
|
|
|
->with('success', 'Label Created Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Labels $label)
|
|
|
|
{
|
2022-03-05 16:58:25 +01:00
|
|
|
$labels = DB::table('labels_assigned as las')
|
2023-08-18 11:33:26 +02:00
|
|
|
->leftJoin('pricings as p', 'las.service_id', 'p.service_id')
|
|
|
|
->leftJoin('servers as s', 'las.service_id', 's.id')
|
|
|
|
->leftJoin('shared_hosting as sh', 'las.service_id', 'sh.id')
|
|
|
|
->leftJoin('reseller_hosting as r', 'las.service_id', 'r.id')
|
|
|
|
->leftJoin('domains as d', 'las.service_id', 'd.id')
|
|
|
|
->where('las.label_id', $label->id)
|
2022-03-05 16:58:25 +01:00
|
|
|
->get(['p.service_type', 'p.service_id', 's.hostname', 'sh.main_domain as shared', 'r.main_domain as reseller', 'd.domain', 'd.extension']);
|
|
|
|
|
|
|
|
return view('labels.show', compact(['label', 'labels']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Labels $label)
|
|
|
|
{
|
2022-11-09 05:18:25 +01:00
|
|
|
if ($label->delete()) {
|
|
|
|
Cache::forget('labels_count');
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
Labels::deleteLabelAssignedAs($label->id);
|
2022-05-14 16:15:20 +02:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
Cache::forget('all_labels');
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
return redirect()->route('labels.index')
|
|
|
|
->with('success', 'Label was deleted Successfully.');
|
|
|
|
}
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('labels.index')
|
2022-11-09 05:18:25 +01:00
|
|
|
->with('error', 'Label was not deleted.');
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
}
|