0

我有这个输出print_r($mailable)

Illuminate\Mail\SendQueuedMailable Object
(
    [mailable:protected] => App\Mail\Expired Object
        (
            [user:protected] => App\User Object
                (
                    [fillable:protected] => Array
                        (
                            [0] => name
                            [1] => email
                            [2] => password
                            [3] => demo
                            [4] => email_demo
                        )

                    [hidden:protected] => Array
                        (
                            [0] => password
                            [1] => remember_token
                        )

                    [connection:protected] => 
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [perPage:protected] => 15
                    [incrementing] => 1
                    [timestamps] => 1
                    [attributes:protected] => Array
                        (
                            [id] => 1020

我怎样才能访问最后一行[id] => 1020

我尝试使用 $mailable->user、$mailable->mailable,但它显示:

Undefined property: Illuminate\Mail\SendQueuedMailable::$user
4

1 回答 1

0

您需要的属性是protected,因此您无法从外部访问它们,并且API不提供 getter 方法。从 5.4 版本开始,Laravel 已经制作了这些属性public

我建议要么更新到较新版本的 Laravel,编写自己的自定义类来添加访问器方法,要么使用撬棒技术将受保护的变量强制进入公共 API。

于 2019-07-23T16:08:05.187 回答