app/Http/ApiControllers/NotificationTokenController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
              'token'        =>  'required',
              'subscribe'    =>  'required',
              'user_id'      =>  'required|exists:user,id'
          ]);
         if ($validator->fails()) {
             $this->setError('400');
             $messages=[];
             foreach ($validator->messages()->toArray() as $key=>$value) {
                  $messages[] = (object)['attribue' => $key, 'message' => $value[0]];
             }
             $this->setValidationError(['validation' => $messages]);
             return $this->response('400');
         }
         $notificationtoken = $request->all();
         if ($this->notificationTokenInterface->exist($request->user_id, $request->token)) {
             $result = $this->notificationTokenInterface->update($notificationtoken);
             if (isset($result)) {
               $this->data(array('id' =>  $result->id));
             }
         }else{
             $result = $this->notificationTokenInterface->store($notificationtoken);
             if (isset($result)) {
               $this->data(array('id' =>  $result->id));
             }
         }
         return $this->response('201');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'token' => 'required' , 'subscribe' => 'required' , 'user_id' => 'required|exists:user,id' ] ) ; if ( $ validator -> fails ( ) ) { $ this -> setError ( '400' ) ; $ messages = [ ] ; foreach ( $ validator -> messages ( ) -> toArray ( ) as $ key => $ value ) { $ messages [ ] = ( object ) [ 'attribue' => $ key , 'message' => $ value [ 0 ] ] ; } $ this -> setValidationError ( [ 'validation' => $ messages ] ) ; return $ this -> response ( '400' ) ; } $ notificationtoken = $ request -> all ( ) ; if ( $ this -> notificationTokenInterface -> exist ( $ request -> user_id , $ request -> token ) ) { $ result = $ this -> notificationTokenInterface -> update ( $ notificationtoken ) ; if ( isset ( $ result ) ) { $ this -> data ( array ( 'id' => $ result -> id ) ) ; } } else { $ result = $ this -> notificationTokenInterface -> store ( $ notificationtoken ) ; if ( isset ( $ result ) ) { $ this -> data ( array ( 'id' => $ result -> id ) ) ; } } return $ this -> response ( '201' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// dd($this->notificationTokenInterface->exist($request->id, $request->token));