dongzhuo5185 2015-10-20 16:50
浏览 36
已采纳

如何从PHP文件中将变量放入刀片中

I'm trying to make a simple "forgot password" function, so everything works but I don't know how to put in my variabel into blade file.

Here's my source:

public function postForgot(Request $request) {

    $token = bin2hex(openssl_random_pseudo_bytes(16));

    $this->validate($request, [
        'email' => 'required|email|max:255|min:3',

    ]);

    if (User::where('email', '=', $request->input('email'))->exists()) {

        // user found

        Mail::send('emails.forgot', function($message) {

            $message->to($_POST['email'],$_POST['email'])->subject('We almost got your password back...');

        });

    } else {

        echo "Not found user";

    }

}

Route file:

    Route::get('/forgot/new_password', [
    'uses' => '\Zyllox\Http\Controllers\AuthController@getForgotNewPassword',

]);

Route::post('/forgot/new_password', [
    'uses' => '\Zyllox\Http\Controllers\AuthController@postForgotNewPassword',
    'as' => 'auth.new_pass',
    'middleware' => ['guest'],
]);

Here's my simple blade file:

Here's your token m8 : {{ $token }}

I want the $token variable to work inside the blade file.

Thanks!

  • 写回答

1条回答 默认 最新

  • doulingzhuang3079 2015-10-20 21:07
    关注

    You need to pass your token into the template data array in the Mail::send() function (second parameter).

    public function postForgot(Request $request) {
        $token = bin2hex(openssl_random_pseudo_bytes(16));
        $this->validate($request, [
            'email' => 'required|email|max:255|min:3',
        ]);
        if (User::where('email', '=', $request->input('email'))->exists()) {
            Mail::send('emails.forgot',['token' => $token], function($message) {
                $message->to($_POST['email'],$_POST['email'])->subject('We almost got your password back...');
            });
        } else {
            echo "Not found user";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀