dd()读取var_dump()无法读取的值(dd() reads values that var_dump() can't read)
在我的一个控制器中,我使用变量
$members
调用一个视图:$members = Member::orderBy("created_at", "desc")->get();
然后在视图中我遍历所有成员的组:
@foreach ($members as $group) <?php $group = $group->group(); ?> <b>{{ $group->title }}</b> // fails @endforeach
这会抛出一个
Trying to get property of non-object
异常的Trying to get property of non-object
。 如果我做@foreach ($member as $group) <?php $group = $group->group(); ?> <?php dd($group); ?> // works <b>{{ $group->title }}</b> // fails @endforeach
我可以看到所有
attributes
数组都填充了我想要的所有值。 为什么dd()
读取我无法使用{{ $var }}
读取的值?
@foreach ($member as $group) <?php $group = $group->group(); ?> <?php var_dump($group); ?> // fails <b>{{ $group->title }}</b> // fails @endforeach
也失败了。
In one of my controllers I call a view with the variable
$members
:$members = Member::orderBy("created_at", "desc")->get();
Then in the view I loop over all the member's groups:
@foreach ($members as $group) <?php $group = $group->group(); ?> <b>{{ $group->title }}</b> // fails @endforeach
This throws a
Trying to get property of non-object
exception. If I do@foreach ($member as $group) <?php $group = $group->group(); ?> <?php dd($group); ?> // works <b>{{ $group->title }}</b> // fails @endforeach
I can see all the
attributes
array populated with all the values I want. Why candd()
read values I can't read using{{ $var }}
?
@foreach ($member as $group) <?php $group = $group->group(); ?> <?php var_dump($group); ?> // fails <b>{{ $group->title }}</b> // fails @endforeach
fails as well.
原文:https://stackoverflow.com/questions/32300334
最满意答案
是的,这两个都很好,并且做了完全相同的事情,正如你所注意到的那样。
Yes, both of these are fine, and do exactly the same thing, as you've noticed.
相关问答
更多-
您不能使用syntax-rules来执行此操作,但是您可以使用syntax-case ,使用使用free-identifier=? 。 这是一个例子: (define-syntax (remove-id stx) (syntax-case stx () ((_ head ()) #''()) ((_ head (next tail ...)) (free-identifier=? #'head #'next) #'(remove-id head (tail ...)) ...
-
这个球拍编码如何改善照应 - >或 - >>宏?(How can this racket code for an anaphoric -> or ->> macro be improved?)[2022-08-15]
这是一种方法。 首先定义一个使用显式的版本(在它下面称为>>>)。 >>的定义只是生成一个标识符并将其交给>>>。 #lang racket (define-syntax (>>> stx) (syntax-case stx () [(_ it x) #'x] [(_ it x (y ...) rest ...) #'(let ([it x]) (>>> it (y ...) rest ...))])) (>>> it (range ... -
如何在Racket中将define-syntax与syntax-case分开(how to separate define-syntax from syntax-case in Racket)[2023-06-04]
是的,这两个都很好,并且做了完全相同的事情,正如你所注意到的那样。 Yes, both of these are fine, and do exactly the same thing, as you've noticed. -
如何使用宏在Racket中实现define-type和type-case?(How to implement define-type and type-case in Racket using macros?)[2022-08-31]
你好像在问一个以上的问题。 首先,Typed Racket有一个define-type但它可能与#lang plai的版本略有不同。 你可以在这里看到plai的define-type和type-case 。 其次,你的宏有几个问题。 1) syntax-rules子句的右侧是将define-type的结果应用为函数,这将不起作用。 尝试使用begin来组合表达式。 2)您对def-user-type宏的使用不遵循定义。 该定义需要零个或多个(field-name type)对,但在Blah你给() ,它不是 ... -
b ...允许零个或多个表达式,而对于b1 b2 ... , b1需要是表达式,而b2 ...是零个或多个表达式。 由于你不希望人们写一个无体的let , b1 b2 ...形式强制执行至少一个身体表达。 你知道正则表达式吗? 可以想象b ...类似于.* ,而b1 b2 ...更像是..* 。 b ... allows zero or more expressions, whereas for b1 b2 ..., b1 is required to be an expression, while b2 ...
-
球拍/方案 - 语法 - 案例(Racket / Scheme - Syntax-Case)[2023-12-27]
#'(var var2 var3 ...)确实不是一个列表。 它是一个包装列表的语法对象。 您应该使用syntax->list将项目提取到列表中,因此您的后卫应该如下所示: (all-ids? (syntax->list #'(var var2 var3 ...))) #'(var var2 var3 ...) is indeed not a list. It's a syntax object that wraps a list. You should use syntax->list to extra ... -
定义语法参数和用法(Define-Syntax Arguments and Usage)[2023-02-25]
我设法通过更多的搜索找到了关于模式和定义语法的详细文档。 如果有其他人好奇,请点击这里链接: http : //www.cs.uml.edu/~giam/91.531/Textbooks/RKDybvig.pdf I managed to find a detailed document about patterns and define-syntax through a little bit more search. If anybody else is curious, here is the link ... -
Racket Macro如何将Ellipses传递给Helper功能?(Racket Macro How to Pass Ellipses to Helper function?)[2023-09-02]
with-syntax模式的左侧也可以有省略号,因此可以使用以下内容: (define-syntax (test stx) (syntax-case stx () [(_ body ...) (with-syntax ([(body0 ...) (process-body #'(body ...))]) #'(begin body0 ...))])) 基本思想是如果process-body返回转换后的body元素,我们就可以将它们与begin一起引入。 您的proces ... -
使用Racket进行语言扩展,通过宏定义辅助函数(Language extension using Racket, defining helper functions via macros)[2022-12-19]
问题是hello是在tinylang.rkt的词法范围中定义的,但是你希望它在try.rkt范围内。 您可以使用datum->syntax来设置一段语法的词法上下文。 这将解决问题: #lang racket ; here we redefine module begin. (provide (all-defined-out) (except-out (all-from-out racket) #%module-begin) (rename-out [module-be ... -
Racket图的语法(Syntax for Racket plot)[2022-04-28]
问题是您正在阅读5.3.3的文档,但安装了5.1.3。 在5.3.3版本中,程序: #lang racket (require plot) (plot (function sin (- pi) pi #:label "y = sin(x)")) 按预期工作。 要么从http://racket-lang.org/download/获取新版本,要么查看旧文档: http : //download.racket-lang.org/docs/5.1.3/html/plot/plot html的?q =剧情 The ...