Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\IPCreateRequest;
- use App\Http\Requests\IPEditRequest;
- use App\IP_Pool;
- use Illuminate\Http\Request;
- use Illuminate\Support\ViewErrorBag;
- class IPController extends Controller
- {
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\IP_Pool $iP_Pool
- *
- * @return \Illuminate\Http\Response
- */
- public
- function edit(IP_Pool $ip)
- {
- return view("ip.edit", ["ip" => $ip]);
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\IP_Pool $iP_Pool
- *
- * @return \Illuminate\Http\Response
- */
- public
- function update(IPEditRequest $request, IP_Pool $ip)
- {
- // get validated values
- $validated = $request->validated();
- // is there an entry for the ip -> search
- $found = IP_Pool::where("ip", "=", $validated['edit_ip'])->get();
- // found an ip? yes? is it the same (same id)?
- if (optional($found)->count() > 1 || (optional($found)->count() == 1 && $found->first()->id != $ip->id))
- {
- // ip already in use with different id
- return back()->withInput()->with("errors", "IP wird bereits verwendet!");
- } else
- {
- // assign values
- $ip->ip = $validated['edit_ip'];
- $ip->name = $validated['edit_name'];
- // something changed?
- if ($ip->isDirty())
- {
- // save it
- $ip->save();
- // return with info
- return redirect()->route("ip.edit", ["ip" => $ip->id])->with("status", "Daten erfolgreich gespeichert");
- }
- // nothing changed. just return
- return redirect()->route("ip.edit", ["ip" => $ip->id]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement