Last active
July 18, 2017 22:05
-
-
Save abada/7a05996904d740a071b89470e565b839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services; | |
use Validator; | |
use App\Models\Store; | |
use App\Models\User; | |
class UserService | |
{ | |
private $storeModel; | |
private $userModel; | |
protected $guard = 'user'; | |
public function __construct(User $userModel, Store $storeModel) | |
{ | |
$this->userModel = $userModel; | |
$this->storeModel = $storeModel; | |
} | |
public function create($request) | |
{ | |
$validator = Validator::make($request->all(), [ | |
'store_name' => 'required|max:30', | |
'store_url' => 'required|max:30|regex:/[a-zA-Z0-9\_\. ]+$/|unique:stores,username', | |
'first_name' => 'required|max:255', | |
'mobile' => 'required|numeric|unique:users' | |
]); | |
if ( $validator->fails() ) { | |
return array('case'=>"validator",'data'=>$validator); | |
} | |
$store = $this->storeModel->create([ | |
'name' => $request->input('store_name'), | |
'username' => strtolower($request->input('store_url')) | |
]); | |
$user = $this->userModel | |
::create([ | |
'first_name' => $request->input('first_name'), | |
'mobile' =>(int) $request->input('mobile'), | |
'store_id' => $store->id | |
]); | |
return $user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment