opnform/app/Http/Controllers/Auth/UserController.php

35 lines
758 B
PHP
Raw Normal View History

2022-09-20 19:59:52 +00:00
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Resources\UserResource;
2022-09-20 19:59:52 +00:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
/**
* Get authenticated user.
*/
public function current(Request $request)
{
return new UserResource($request->user());
2022-09-20 19:59:52 +00:00
}
2024-02-23 10:54:12 +00:00
public function deleteAccount()
{
2022-09-20 19:59:52 +00:00
$this->middleware('auth');
if (Auth::user()->admin) {
return $this->error([
2024-02-23 10:54:12 +00:00
'message' => 'Cannot delete an admin. Stay with us 🙏',
2022-09-20 19:59:52 +00:00
]);
}
Auth::user()->delete();
2024-02-23 10:54:12 +00:00
2022-09-20 19:59:52 +00:00
return $this->success([
2024-02-23 10:54:12 +00:00
'message' => 'User deleted.',
2022-09-20 19:59:52 +00:00
]);
}
}