我向客户收取下载的文件后,我需要将该文件存储在数据库的表中。 我现在正在尝试的是不行。我认为我的查询是错误的等等。这是我正在扩展的教程的一部分here本教程使用会话,我需要将它转换为只检查用户的id是否等于数据库中经过身份验证的用户。 / p>
Route::post('/buy/{id}', function($id)
{
/*1. check and see if user is logged in before trying to buy*/
if(Auth::check()) {
Stripe::setApiKey(Config::get('laravel-stripe::stripe.api_key'));
//$download = new Download;
$download = Download::find($id);
//dd($download);
//stripeToken is form name, injected into form by js
$token = Input::get('stripeToken');
/* 2. If user is logged in charge the card*/
try {
$charge = Stripe_Charge::create(array(
"amount" => $download->price,
"currency" => "gbp",
"card" => $token,
"description" => 'Order: ' . $download->name)
);
// If we get this far, we've charged the user successfully
/* 3.Insert file user downloaded into database purchase table
only if user id is equal to auth id in users table*/
$user = DB::table('users')
->where('id', 'Auth::user()->id')
->exists();
//dd($user);
//$download->where('user_id', Auth::user()->id)->exist;
return Redirect::to('confirmed', '$download');
} catch(Stripe_CardError $e) {
// Payment failed
return Redirect::to('buy/'.$id)->with('message', 'Your payment has failed.');
}
}
});