Home >Backend Development >PHP Tutorial >About laravel's getter: get{xxxx}Attribute and data type issues
<code>laracast上教学用的方法,成功获取了tag_list</code>
<code>模仿写的获取role_list,报错了</code>
<code>如果直接在controller里面这样直接用$user->roles是能成功获取的</code>
Question:
1. What is the reason for the above three pictures?
2. Can it be solved so that the content found through $id
in the traditional resource
controller can also be directly called using the xxxx
in get{xxxx}Attribute
?
3. In the picture below, are the results obtained by these two parameter transfer methods the same structure?
<code>laracast上教学用的方法,成功获取了tag_list</code>
<code>模仿写的获取role_list,报错了</code>
<code>如果直接在controller里面这样直接用$user->roles是能成功获取的</code>
Question:
1. What is the reason for the above three pictures?
2. Can it be solved so that the content found through $id
in the traditional resource
controller can also be directly called using the xxxx
in get{xxxx}Attribute
?
3. In the picture below, are the results obtained by these two parameter transfer methods the same structure?
<code><?php /** * Created by PhpStorm. * User: shellus * Date: 2016-08-05 * Time: 12:57 */ class Test { /** * 魔术方法,访问类成员时,会转向调用到此方法 */ function __get($name) { return call_user_func(array($this, $name)); } public function users(){ return ['a','b','c']; } } $test = new Test(); var_dump($test -> users);</code>
Is this what you are asking?
1, as mentioned above, it is obtained through the magic method
2, all subclass instances of model can be used in this way
3, all returned are model subclasses
Why can’t I like it yet