Paragonik/paragonik-backend/app/Http/Controllers/Auth/StoreRegisterController.php

91 lines
2.4 KiB
PHP
Raw Normal View History

2019-12-16 13:02:21 +01:00
<?php
namespace App\Http\Controllers\Auth;
use App\Models\Store;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class StoreRegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function createAPI(Request $request)
{
$store = Store::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
return response()->json($store, 201);
}
protected function create(Request $request)
{
$store = Store::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
if(Auth::guard('store')->attempt([
'email' => $request->email,
'password' => $request->password]))
{
return redirect()->intended(route('store.dashboard'));
}
}
public function showRegisterForm(){
return view('auth.store-register');
}
}