Ответы пользователя по тегу Twig
  • Eloquent ORM и Twig ошибка, кто сталкивался?

    bestxp
    @bestxp Автор вопроса
    Да бывает пару дней убьешь на поиски, а потом ларчик открывается просто

    нужно переопрделить базовый класс для шаблонов и там переопределить метод

    /**
         * {@inheritdoc}
         */
        protected function getAttribute(
            $object,
            $item,
            array $arguments = [],
            $type = Twig_Template::ANY_CALL,
            $isDefinedTest = false,
            $ignoreStrictCheck = false
        )
        {
            // We need to handle accessing attributes on an Eloquent instance differently
            if (Twig_Template::METHOD_CALL !== $type and is_a($object, 'Illuminate\Database\Eloquent\Model')) {
                // We can't easily find out if an attribute actually exists, so return true
                if ($isDefinedTest) {
                    return true;
                }
    
    
    
                // Call the attribute, the Model object does the rest of the magic
                return $object->$item;
            } else {
                return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
            }
        }


    подглядел twig bridge for laravel
    Ответ написан
    Комментировать