我如何从PHP文件中插入一个变量到刀片

时间:2015-10-20 16:50:17

标签: php laravel blade

我正在尝试制作一个简单的“忘记密码”功能,所以一切正常但我不知道如何将我的变量放入刀片文件中。

这是我的来源:

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::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 your token m8 : {{ $token }}

我希望$ token变量在刀片文件中工作。

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要将令牌传递到Mail::send()函数(第二个参数)中的模板数据数组中。

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";
    }
}