微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误:尝试访问 null 类型值的数组偏移量php 8

如何解决错误:尝试访问 null 类型值的数组偏移量php 8

我到处寻找这个解决方案,但似乎没有针对 PHP 8 的特定解决方案,因为我理解这个错误只是一个 PHP 错误,所以我正在尝试使用联系表格发送电子邮件,这是我的代码:

控制器:

public function _msg(Request $request,$id)
{
    $info = entreprise::find($id);
    //dd($info->mail);

    $this->validate($request,[
        'nom'=> 'required','email'=> 'required|email','telephone'=> array(
            'regex:/^(?:(?:(?:\+|00)212[\s]?(?:[\s]?\(0\)[\s]?)?)|0){1}(?:5[\s.-]?[2-3]|6[\s.-]?[13-9]){1}[0-9]{1}(?:[\s.-]?\d{2}){3}$/','digits:10'
        ),'message'=> 'required|min:10|max:500'
    ]); 


    $information = [
        'name' => $request->nom,'phone' => $request->Tel,'email' => $request->email,'message' => $request->message
    ];

    //dd($information);

    Mail::to('jon.reed10C@gmail.com')->send(new SendEmail($information));

    $msg = new messages;

    $msg->nom = $request->nom;
    $msg->email = $request->email;
    $msg->Tel = $request->Tel;
    $msg->message = $request->message;
    $msg->id_en = $request->id;

    $msg->save();

    return back()->with('success','Merci de nous contacter !');
}

可邮寄类:

class SendEmail extends Mailable
{
use Queueable,SerializesModels;

public $information;

public function __construct($information)
{
    $this->info = $information;
}


public function build()
{
    return $this->subject('Contact message')->view('email.msgSend');
}
}

消息视图:

<h1>Message</h1>
 >>>>>>>>>> <p>Nom: {{ $information['name']}}</p>
<p>Email: {{ $information['email']}}</p>
<p>Telephone: {{ $information['phone']}}</p>
<p>Message: {{ $information['message']}}</p>

错误指向我用消息视图中的箭头指向的同一位置,我尝试转储 $information 并返回一个包含正确信息的数组,我转储了 $information['name'] 并返回了正确命名,我尝试了我找到的所有解决方案,但没有任何效果

解决方法

您必须将 $this->info 更改为 $this->information

因为您正在为尚未声明的属性赋值。您的刀片使用定义为属性的值。您定义的属性仍然为空,因为您试图将您的值添加到不存在的属性中 :)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。