Jerry/app/Http/Controllers/Api/customerController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
Store a newly created resource in storage.
@param  Request  $request
@return Response
Store a newly created resource in storage . @param Request $request @return Response
public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'firsname' => 'min:1|max:255',
            'lastname' => 'min:1|max:255',
            'email' => 'required|email|unique:customers,email',
            'phone' => '',
            'password' => 'required|min:6|max:25',
            'birthday' => '|date',
            'gender' => 'in:F,M',
            'customer_type_id' => 'exists:customers_type,customer_type_id',
        ]);
        if ($validator->fails()) {
            $this->_response = [
                'error' => true,
                'customer' => $validator->messages()
            ];
            return response()->json($this->_response);
        }
        try {
            $hasher = app()->make('hash');
            $input = $request->all();
            $input['password'] = $hasher->make($request->input('password'));
            $customer = Customer::create($input);
            $this->_response = [
                'error' => false,
                'msg' => 'The customer has been created successfully',
                'customer' => $customer->customer_id,
            ];
        } catch (Exception $e) {
            $this->_response = [
                'error' => 'true',
                'msg' => $e->getMessage(),
                'customer' => null,
            ];
        }
        return response()->json($this->_response);
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'firsname' => 'min:1|max:255' , 'lastname' => 'min:1|max:255' , 'email' => 'required|email|unique:customers,email' , 'phone' => '' , 'password' => 'required|min:6|max:25' , 'birthday' => '|date' , 'gender' => 'in:F,M' , 'customer_type_id' => 'exists:customers_type,customer_type_id' , ] ) ; if ( $ validator -> fails ( ) ) { $ this -> _response = [ 'error' => true , 'customer' => $ validator -> messages ( ) ] ; return response ( ) -> json ( $ this -> _response ) ; } try { $ hasher = app ( ) -> make ( 'hash' ) ; $ input = $ request -> all ( ) ; $ input [ 'password' ] = $ hasher -> make ( $ request -> input ( 'password' ) ) ; $ customer = Customer :: create ( $ input ) ; $ this -> _response = [ 'error' => false , 'msg' => 'The customer has been created successfully' , 'customer' => $ customer -> customer_id , ] ; } catch ( Exception $ e ) { $ this -> _response = [ 'error' => 'true' , 'msg' => $ e -> getMessage ( ) , 'customer' => null , ] ; } return response ( ) -> json ( $ this -> _response ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/*$user = $customer;
            \Mail::send('emails.demo', ['user' => $user], function ($m) use ($user) {
                $m->to($user->email, $user->name)->subject('Your Reminder!');
            });*/