Ejemplo n.º 1
0
 /**
  * Display the password reset view for the given token.
  *
  * @param  string  $token
  * @return \Illuminate\Http\Response
  */
 public function getConfirm($token = null)
 {
     if (is_null($token)) {
         return responseJsonNotFound(['message' => trans(Confirmation::NULL_TOKEN), 'errors' => trans(Confirmation::NULL_TOKEN)]);
     }
     $credentials = ['token' => $token];
     $response = Confirmation::confirm($credentials, function ($user) {
         $this->confirmAccount($user);
     });
     switch ($response) {
         case Confirmation::ACCOUNT_CONFIRMATION:
             return responseJsonOk(['message' => trans($response), 'data' => null]);
         default:
             return responseJsonUnprocessableEntity(['message' => trans($response), 'errors' => ['email' => trans($response)]]);
     }
 }
Ejemplo n.º 2
0
 public function getIndex(Request $request, $id = null)
 {
     if (method_exists($this, 'index')) {
         return $this->index($request, $id);
     }
     $responseData = array();
     if (is_null($id)) {
         $queryResult = $this->validateQuery($request, $this->model);
     } else {
         $modelClass = $this->model;
         $queryResult = $modelClass::where($modelClass::getPrimaryKeyName(), $id)->first();
         if ($queryResult instanceof Model) {
             $queryResult = $queryResult->toArray();
         } else {
             $queryResult = null;
         }
         $responseData = ["data" => $queryResult];
         if (is_null($queryResult)) {
             $responseData = $this->setMessage($responseData, $this->getIndexMessage404());
             return responseJsonNotFound($responseData);
         } else {
             $responseData = $this->setMessage($responseData, $this->getIndexMessage200());
             return responseJsonOk($responseData);
         }
     }
     if ($queryResult instanceof Collection) {
         $responseData = ["data" => $queryResult->toArray()];
     }
     if ($queryResult instanceof LengthAwarePaginator) {
         $responseData = $queryResult->toArray();
         $responseData = $this->buildPaginationUrl($responseData, $request);
     }
     if (count($responseData['data']) < 1) {
         $responseData['data'] = null;
         $responseData = $this->setMessage($responseData, $this->getIndexMessage404());
     } else {
         $responseData = $this->setMessage($responseData, $this->getIndexMessage200());
     }
     return responseJsonOk($responseData);
 }