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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?