R
R
Ruslan Absalyamov2018-08-25 14:17:17
Laravel
Ruslan Absalyamov, 2018-08-25 14:17:17

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);
    }
}

In ValidateLanding
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
        ];
    }
}

The problem is that when it comes to the check line if (!$this->name && !$this->phone){
like And so on, then it simply does not process $this->getMessage and throws out a 500 error. Although the data is there.
Here is a screenshot from the debugger
5b813a7da28aa934963157.png
. I left the name and phone number empty for this check to work, but it goes to return $this->getMessage and an error occurs

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-08-25
@rusline18

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 question

Ask a Question

731 491 924 answers to any question