N
N
Nikolai Steshenko2021-03-17 11:45:34
Laravel
Nikolai Steshenko, 2021-03-17 11:45:34

How to correctly return an error from an if?

There is a code designed to check the data that came from the form with the data in the database. Everything works, but I cannot return an error if the data from the database and the data from the form do not match. How to solve the problem correctly?

public function Emptyinvate($invait)
  {
     $token = Invaite::all()->first();
  
      if($invait == $token->invaite_token){
        return $invait; 
      }else{
      return responсe(['error' => ['message' => 'Приглашение не существует']]);  
    }
}
  
    protected function create(array $data)
    {
    $invait = $this->Emptyinvate($data['invaite_token']);
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
      'invaite_token' => $invait,
            'password' => Hash::make($data['password']),
        ]);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-03-17
@delphinpro

Read this section carefully and all questions will disappear: https://laravel.com/docs/8.x/validation
Ru: https://github.com/russsiq/laravel-docs-8.x-ru/blo.. .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question