Answer the question
In order to leave comments, you need to log in
Why am I getting a 500 error?
I don’t understand why my framework throws a 500 error. It worked like this when it was in pure php without a framework, then everything worked fine, but now it doesn’t even reach the getMessage () method
Post request goes using ajax. Previously, there was no csrf token, now it has become, but in principle this is not the point
class LandingController extends Controller
{
public function index(Request $request)
{
$validate = new ValidateLanding($request->all());
return json_decode($validate->getValidate(), JSON_UNESCAPED_UNICODE);
}
}
namespace Latina;
interface ValidateData
{
/**
* Если все верно то сохраняет в бд и отправляют по email лид
* Проверка на заполнение телефона или email
* @return array
*/
public function getValidate();
/**
* Выводит сообщение о результате
* @param bool $error
* @param string $message
* @return array
*/
public function getMessage(bool $error, string $message);
}
class ValidateLanding implements ValidateData
{
private $name;
private $phone;
public $result = [];
public function __construct(array $data)
{
$this->phone = $data['phone'];
$this->name = $data['name'];
}
public function getValidate()
{
if (!$this->name && !$this->phone){
return $this->getMessage(true, 'Заполните имя и телефон');
} elseif (!$this->name){
return $this->getMessage(true, 'Заполните имя');
} elseif (!$this->phone){
return $this->getMessage(true, 'Заполните телефон');
} else {
preg_match('/[\d]+/', $this->name, $matches);
if (strlen($this->phone) != 16){
return $this->getMessage(true, 'Некорректный телефон');
}
if ($matches[0]){
return $this->getMessage(true, 'Имя не должна содержать цифры');
}
return $this->getMessage(false, 'Сообщение отправлено');
}
}
public function getMessage(bool $error, string $message)
{
return $this->result = [
'error' => $error,
'message' => $message
];
}
}
if (!$this->name && !$this->phone){
Answer the question
In order to leave comments, you need to log in
Look at the error in the logs...
And no, it's not that mistake.
storage/logs/laravel.log
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question