@@ 52-70 (lines=19) @@ | ||
49 | * @param EditLocation $request |
|
50 | * @return \Illuminate\Http\RedirectResponse |
|
51 | */ |
|
52 | public function store(EditLocation $request) |
|
53 | { |
|
54 | $this->authorize('store', Location::class); |
|
55 | ||
56 | //Get the site id of the old or newly created site |
|
57 | if (!empty($request->input('new_site_name'))) |
|
58 | { |
|
59 | //Create a new site |
|
60 | $site = Site::create([ 'name' => $request->input('new_site_name') ]); |
|
61 | $site_id = $site->id; |
|
62 | } else { |
|
63 | $site_id = $request->input('site'); |
|
64 | } |
|
65 | ||
66 | $location = Location::create([ 'name' => $request->input('name'), 'site_id' => $site_id ]); |
|
67 | ||
68 | return redirect()->route('location.show', $location->id) |
|
69 | ->with('success', 'Location created successfully'); |
|
70 | } |
|
71 | ||
72 | /** |
|
73 | * Display the specified resource. |
|
@@ 111-130 (lines=20) @@ | ||
108 | * @param int $id |
|
109 | * @return \Illuminate\Http\RedirectResponse |
|
110 | */ |
|
111 | public function update(EditLocation $request, $id) |
|
112 | { |
|
113 | $this->authorize('update', Location::class); |
|
114 | ||
115 | //Get the site id of the old or newly created site |
|
116 | if (!empty($request->input('new_site_name'))) |
|
117 | { |
|
118 | //Create a new site |
|
119 | $site = Site::create([ 'name' => $request->input('new_site_name') ]); |
|
120 | $site_id = $site->id; |
|
121 | } else { |
|
122 | $site_id = $request->input('site'); |
|
123 | } |
|
124 | ||
125 | //Update the location with the supplied name and the site |
|
126 | Location::findOrFail($id)->update([ 'name' => $request->input('name'), 'site_id' => $site_id ]); |
|
127 | ||
128 | return redirect()->route('location.show', $id) |
|
129 | ->with('success', 'Location updated successfully'); |
|
130 | } |
|
131 | ||
132 | /** |
|
133 | * Remove the specified resource from storage. |