Laravel 5 尝试获取非对象电子邮件的属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29505633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Trying to get property of non-object email
提问by Athar Rajpoot
I have mail code written in my signup function , and i am receiving this error
我在注册功能中写入了邮件代码,但收到此错误
ErrorException in 7c8c0426cb92aba181a5916d6b3e33a6 line 2: Trying to get property of non-object (View: /Users/aliayaz/Adcells-master/resources/views/emails/register-activate.blade.php)
ErrorException in 7c8c0426cb92aba181a5916d6b3e33a6 line 2: Trying to get property of non-object (View: /Users/aliayaz/Adcells-master/resources/views/emails/register-activate.blade.php)
Mail::queueOn('Email-Activation', 'emails.register-activate', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->subject('Welcome ' . $user->first_name);
});
and i have register-activate file under resources/views/emails
我在资源/视图/电子邮件下有注册激活文件
@extends('emails/layouts/default')
@section('content')
<p>Hello {{{ $user->first_name }}},</p>
<p>Welcome to SiteNameHere! Please click on the following link to confirm your SiteNameHere account:</p>
<p><a href="{{{ $activationUrl }}}">{{{ $activationUrl }}}</a></p>
<p>Best regards,</p>
<p>@lang('general.site_name') Team</p>
@stop
this code was working flawlessly under laravel 4.2 and i wanted to upgrade to 5.0
这段代码在 laravel 4.2 下完美运行,我想升级到 5.0
edit 1 : I dont have file named 7c8c0426cb92aba181a5916d6b3e33a6
编辑 1:我没有名为 7c8c0426cb92aba181a5916d6b3e33a6 的文件
回答by Chris
This is an issue specifically with Mail::queue
and all it's subset methods. When data is handled via the queue system, it gets serialised, then unserialised when it hits the email view.
这是一个专门针对Mail::queue
及其所有子集方法的问题。当数据通过队列系统处理时,它会被序列化,然后在到达电子邮件视图时反序列化。
However if you were to change your snippet above to Mail::send
instead, you will find it works.
但是,如果您将上面的代码段改为Mail::send
改为,您会发现它有效。
One approach to handle this is making a site wide decision that only arrays are passed into views.
处理此问题的一种方法是在站点范围内做出仅将数组传递到视图的决定。
回答by Praveen Srinivasan
You have to pass array of data inside the view. You didn't pass $user data inside the view. You have to pass $user variable inside the view. Then only you can access the $user of value
您必须在视图中传递数据数组。您没有在视图中传递 $user 数据。您必须在视图中传递 $user 变量。那么只有你可以访问价值的 $user
$data = array('user' => $user);
Mail::queueOn('Email-Activation', 'emails.register-activate', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->subject('Welcome ' . $user->first_name);
});
then print your view as following
然后打印您的视图如下
<p>Hello {{{ $user['first_name'] }}},</p>
回答by Rohit Batra
try merging the To & Subject logic in one statement.
尝试在一个语句中合并 To & Subject 逻辑。
$m->to($user->email, $user->first_name . ' ' . $user->last_name)->subject('Welcome ' . $user->first_name);
Also can you paste the code in this file "7c8c0426cb92aba181a5916d6b3e33a6" to further see what is causing this issue.
您也可以将代码粘贴到此文件“7c8c0426cb92aba181a5916d6b3e33a6”中以进一步查看导致此问题的原因。
回答by rotvulpix
Make sure that $data['user'] exists and is also an object. Probably that's happening. It's trying to get info from $user and it doesn't exists.
确保 $data['user'] 存在并且也是一个对象。大概就是这么回事。它试图从 $user 获取信息,但它不存在。
回答by Ranjeet Karki
Mail::send('emails.register-activate', $data, function($message) {
$message->to(Input::get('email'), Input::get('username'))
->subject('Verify your email address');
});
if it says input not found the put below code at top of your page
如果它说没有找到输入,请将下面的代码放在您的页面顶部
use Illuminate\Support\Facades\Input;