2024-08-29 11:48:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Hash;
|
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Validator;
|
|
|
|
|
|
|
|
class PublicUserController extends Controller
|
|
|
|
{
|
|
|
|
public function register(Request $request)
|
|
|
|
{
|
|
|
|
$data = $request->all()['user'];
|
|
|
|
if (User::where([ 'email' => $data['email'] ])->count() != 0) {
|
2024-08-29 11:52:16 +02:00
|
|
|
return response()
|
|
|
|
->json('email_taken', 400);
|
2024-08-29 11:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
$user = User::create([
|
|
|
|
...$data,
|
|
|
|
'password' => Hash::make($request->input('password'))
|
|
|
|
]);
|
|
|
|
$user->save();
|
|
|
|
session('user', $user->id);
|
|
|
|
session()->save();
|
|
|
|
}
|
|
|
|
}
|