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