diff --git a/app/Http/Controllers/NoteController.php b/app/Http/Controllers/NoteController.php new file mode 100644 index 0000000..038b84d --- /dev/null +++ b/app/Http/Controllers/NoteController.php @@ -0,0 +1,124 @@ +validate([ + 'service_id' => 'required|string|size:8', + 'note' => 'required|string', + ]); + + try { + $note_id = Str::random(8); + + $a = Note::create([ + 'id' => $note_id, + 'service_id' => $request->service_id, + 'note' => $request->note + ]); + + } catch (\Exception $e) { + + if ($e->getCode() === "23000") { + $message = "A note already exists for this service"; + } else { + $message = "Error inserting note"; + } + + return redirect()->route('notes.create') + ->withInput($request->input())->with('error', $message); + } + + Cache::forget('all_notes'); + + return redirect()->route('notes.index') + ->with('success', 'Note created successfully.'); + } + + public function edit(Note $note) + { + $note = Note::note($note->service_id); + $servers = Server::all(); + $shareds = Shared::all(); + $resellers = Reseller::all(); + $domains = Domains::all(); + $dns = DNS::all(); + $ips = IPs::all(); + + return view('notes.edit', compact(['note', 'servers', 'shareds', 'resellers', 'domains', 'dns', 'ips'])); + } + + public function update(Request $request, Note $note) + { + $request->validate([ + 'service_id' => 'required|string|size:8', + 'note' => 'required|string' + ]); + + $note->update([ + 'service_id' => $request->service_id, + 'note' => $request->note + ]); + + Cache::forget('all_notes'); + Cache::forget("note.$note->service_id"); + + return redirect()->route('notes.index') + ->with('success', 'Note was updated successfully.'); + } + + public function show(Note $note) + { + $note = Note::note($note->service_id); + return view('notes.show', compact(['note'])); + } + + public function destroy(Note $note) + { + if ($note->delete()) { + Cache::forget("all_notes"); + Cache::forget("note.$note->service_id"); + + return redirect()->route('notes.index') + ->with('success', 'Note was deleted successfully.'); + } + + return redirect()->route('notes.index') + ->with('error', 'Note was not deleted.'); + + } + +} diff --git a/app/Models/DNS.php b/app/Models/DNS.php index 6cb1df2..ac52e82 100644 --- a/app/Models/DNS.php +++ b/app/Models/DNS.php @@ -25,4 +25,10 @@ class DNS extends Model return DB::table('d_n_s')->count(); }); } + + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Domains.php b/app/Models/Domains.php index 5172992..59127eb 100644 --- a/app/Models/Domains.php +++ b/app/Models/Domains.php @@ -56,4 +56,9 @@ class Domains extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/IPs.php b/app/Models/IPs.php index 1dbb5eb..c5beddb 100644 --- a/app/Models/IPs.php +++ b/app/Models/IPs.php @@ -47,4 +47,9 @@ class IPs extends Model }); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Note.php b/app/Models/Note.php new file mode 100644 index 0000000..6ab7d6d --- /dev/null +++ b/app/Models/Note.php @@ -0,0 +1,66 @@ +addMonth(1), function () use ($service_id) { + return self::where('service_id', $service_id)->with(['server', 'shared', 'reseller', 'domain', 'dns', 'ip'])->first(); + }); + } + + public static function allNotes() + { + return Cache::remember("all_notes", now()->addMonth(1), function () { + return self::with(['server', 'shared', 'reseller', 'domain', 'dns', 'ip'])->orderBy('created_at', 'desc')->get(); + }); + } + + public function server(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Server::class, 'service_id', 'id'); + } + + public function shared(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Shared::class, 'service_id', 'id'); + } + + public function reseller(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Reseller::class, 'service_id', 'id'); + } + + public function domain(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Domains::class, 'service_id', 'id'); + } + + public function dns(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(DNS::class, 'service_id', 'id'); + } + + public function ip(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(IPs::class, 'service_id', 'id'); + } + +} diff --git a/app/Models/Reseller.php b/app/Models/Reseller.php index fb5c6c6..54c9d47 100644 --- a/app/Models/Reseller.php +++ b/app/Models/Reseller.php @@ -78,4 +78,9 @@ class Reseller extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Server.php b/app/Models/Server.php index 16ad201..e424358 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -234,4 +234,9 @@ class Server extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/app/Models/Shared.php b/app/Models/Shared.php index 3cca635..f26e86b 100644 --- a/app/Models/Shared.php +++ b/app/Models/Shared.php @@ -78,4 +78,9 @@ class Shared extends Model return $this->hasMany(LabelsAssigned::class, 'service_id', 'id'); } + public function note(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(Note::class, 'service_id', 'id'); + } + } diff --git a/resources/views/dns/show.blade.php b/resources/views/dns/show.blade.php index 57329e9..0d267e1 100644 --- a/resources/views/dns/show.blade.php +++ b/resources/views/dns/show.blade.php @@ -88,6 +88,12 @@ +
Note:
+{{$dns->note->note}}
+ @endif +Note:
+{{$domain_info->note->note}}
+ @endif +Service | +Type | +Note Preview | +Actions | +
---|---|---|---|
+ @if(!is_null($n->server)) + {{$n->server->hostname}} + @elseif(!is_null($n->shared)) + {{$n->shared->main_domain}} + @elseif(!is_null($n->reseller)) + {{$n->reseller->main_domain}} + @elseif(!is_null($n->domain)) + {{$n->domain->domain}}.{{$n->domain->extension}} + @elseif(!is_null($n->dns)) + {{$n->dns->dns_type}} {{$n->dns->hostname}} + @elseif(!is_null($n->ip)) + {{$n->ip->address}} + @endif + | ++ @if(!is_null($n->server)) + SERVER + @elseif(!is_null($n->shared)) + SHARED + @elseif(!is_null($n->reseller)) + RESELLER + @elseif(!is_null($n->domain)) + DOMAIN + @elseif(!is_null($n->dns)) + DNS + @elseif(!is_null($n->ip)) + IP + @endif + | +{{strlen($n->note) > 80 ? substr($n->note,0,80)."…" : $n->note}} | ++ + | +
No notes found. | ++ | + | + |
{{$note->note}}
+ curl -sL yabs.sh | bash -s -- -s "{{route('api.store-yabs', [$server_data->id, \Illuminate\Support\Facades\Auth::user()->api_token])}}"
Note:
+{{$server_data->note->note}}
+ @endifFTP Limit | {{$shared->ftp_limit}} |
Note: | +{{$shared->note->note}} | +