megahunt.test/app/Http/Controllers/PublicUserController.php

33 lines
732 B
PHP
Executable File

<?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) {
return response()
->json('email_taken', 400);
}
/**
* @var User
*/
$user = User::create([
...$data,
'password' => Hash::make($request->input('password'))
]);
$user->save();
session('user', $user->id);
session()->save();
}
}