DO NOT TOUCH MENUPLAN-STUFF!!!

This commit is contained in:
Sebastian Davaris 2020-06-29 09:08:49 +02:00
parent 0adc1ebf02
commit c1877cd180
4 changed files with 46 additions and 32 deletions

View File

@ -89,7 +89,7 @@ class MenuPlanController extends Controller
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$data = $request->all(); $data = $request->all();
//FORCED UPDATE
$menuplan = MenuPlan::find($id); $menuplan = MenuPlan::find($id);
$menuplan->update($data); $menuplan->update($data);

View File

@ -117,35 +117,42 @@ class UserController extends Controller
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$data = $request->validate([ $data = $request->all();
"name_first" => "max:255",
"name_last" => "max:255", // $data = $request->validate([
"email" => "email|unique:users", // "name_first" => "max:255",
"password" => "max:60", // "name_last" => "max:255",
"phone" => "unique:users", // "email" => "email|unique:users",
]); // "password" => "max:60",
// "phone" => "unique:users",
// ]);
// Validates if the user is updating itself or another user. // Validates if the user is updating itself or another user.
if($id === Auth::id()) { // if($id === Auth::id()) {
$user = Auth::user(); // $user = Auth::user();
$user->update($data);
$user->save();
}
//TODO: Implement when security's ready!!!
// else if(Auth::user()->hasPermissionTo("user.edit")) {
// $user = User::find($id);
// //
// /** @var User $user */
// $user->update($data); // $user->update($data);
// //
// $user->save(); // $user->save();
// return Response::detect("users.edit", [
// "user" => $user
// ]);
// } // }
return Response::detect("users.edit", [ //TODO: Implement when security's ready!!!
"user" => $user // else if(Auth::user()->hasPermissionTo("user.edit")) {
$user = User::find($id);
/** @var User $user */
$user->update($data);
$user->save();
// }
$users = User::query()->paginate(20);
return Response::detect("users.index", [
"users" => $users
]); ]);
} }
@ -157,17 +164,17 @@ class UserController extends Controller
*/ */
public function destroy($id) public function destroy($id)
{ {
if($id === Auth::id()) { // if($id === Auth::id()) {
$user = Auth::user(); // $user = Auth::user();
$user->delete(); // $user->delete();
} // }
else if(Auth::user()->hasPermissionTo("user.delete")) { // else if(Auth::user()->hasPermissionTo("user.delete")) {
$user = User::find($id); $user = User::find($id);
$user->delete(); $user->delete();
} // }
return view("users.delete"); return redirect()->route("users.index");
} }
/*******************************************/ /*******************************************/

View File

@ -6,12 +6,12 @@
@endsection @endsection
@section("path") @section("path")
<a href="{{ route('users.edit', ['id' => $user]) }}" class="text-white">Rediger Bruger</a> / <a href="{{ route('users.edit', ['user' => $user]) }}" class="text-white">Rediger Bruger</a> /
@endsection @endsection
@section("content") @section("content")
<h1>Rediger Bruger:</h1> <h1>Rediger Bruger:</h1>
<form method="post" action="{{ route("users.update", ['id' => $user]) }}"> <form method="post" action="{{ route("users.update", ['user' => $user]) }}">
@csrf @csrf
@method("put") @method("put")
<label for="name_first">Fornavn:</label> <label for="name_first">Fornavn:</label>

View File

@ -26,7 +26,14 @@
<td>{{ $user->email }}</td> <td>{{ $user->email }}</td>
<td>{{ $user->phone }}</td> <td>{{ $user->phone }}</td>
<td><a href="{{ route("users.edit", [ "user" => $user->id ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td> <td><a href="{{ route("users.edit", [ "user" => $user->id ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
<td><a href=""><img class="w-100" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></a></td> <td>
<form method="post" action="{{ route("users.destroy", [ "user" => $user ]) }}" class="w-100">
@csrf
@method("delete")
<button type="submit"><img class="w-100" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
</form>
</td>
</tr> </tr>
@endforeach @endforeach
</table> </table>