35 lines
814 B
PHP
35 lines
814 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Auth;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
||
|
class UserController extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* Get authenticated user.
|
||
|
*
|
||
|
* @param \Illuminate\Http\Request $request
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
*/
|
||
|
public function current(Request $request)
|
||
|
{
|
||
|
return response()->json($request->user());
|
||
|
}
|
||
|
|
||
|
public function deleteAccount() {
|
||
|
$this->middleware('auth');
|
||
|
if (Auth::user()->admin) {
|
||
|
return $this->error([
|
||
|
'message' => 'Cannot delete an admin. Stay with us 🙏'
|
||
|
]);
|
||
|
}
|
||
|
Auth::user()->delete();
|
||
|
return $this->success([
|
||
|
'message' => 'User deleted.'
|
||
|
]);
|
||
|
}
|
||
|
}
|