I’m working on an application that shows videos using Laravel 10.8. When i updated the UserController.php I get the following error message:
syntax error, unexpected variable "$token_time", expecting "function" or "const"
i have looked all over google for an answer on how to fix the error. What should i do?
// *******************************************Custom code promotion links
$token_time = "";
if (isset($_REQUEST['token'])) {
//date_default_timezone_set("America/Chicago");
$creator_id = $user->id;
$token_time = decrypt($_REQUEST['token']);
$expired_time_link = DB::table("promotion_campaign")->where('creator_id', $creator_id)->get();
$expired_time_link = $expired_time_link[0]->expired_at;
if (strtotime(now()) >= strtotime($expired_time_link)) {
$username = $user->username;
return redirect()->to('/' . $username);
} else {
return view('users.profile', [
'user' => $user,
'updates' => $updates,
'hasPages' => $updates->hasPages(),
'totalPosts' => $user->updates()->select('updates.id', 'updates.user_id')->count(),
'totalPhotos' => $user->media()->where('media.type', 'image')->count(),
'totalVideos' => $user->media()->where('media.type', 'video')->count(),
'totalMusic' => $user->media()->where('media.type', 'music')->count(),
'totalFiles' => $user->media()->where('media.type', 'file')->count(),
'totalEpub' => $user->media()->where('media.type', 'epub')->count(),
'_stripe' => $_stripe,
'checkSubscription' => $checkSubscription ?? null,
'media' => $media,
'mediaTitle' => $mediaTitle,
'sortPostByTypeMedia' => $sortPostByTypeMedia,
'allPayment' => $allPayment,
'paymentIncomplete' => $paymentIncomplete ?? null,
'likeCount' => $likeCount,
'categories' => $categories,
'paymentGatewaySubscription' => $paymentGatewaySubscription->payment_gateway ?? null,
'subscriptionsActive' => $subscriptionsActive,
'plans' => $plans,
'userPlanMonthlyActive' => $userPlanMonthlyActive ?? null,
'userProducts' => $userProducts,
'shopCategories' => $shopCategories ?? null,
'token_time' => $token_time
]);
}
} else {
return view('users.profile', [
'user' => $user,
'updates' => $updates,
'hasPages' => $updates->hasPages(),
'totalPosts' => $user->updates()->select('updates.id', 'updates.user_id')->count(),
'totalPhotos' => $user->media()->where('media.type', 'image')->count(),
'totalVideos' => $user->media()->where('media.type', 'video')->count(),
'totalMusic' => $user->media()->where('media.type', 'music')->count(),
'totalFiles' => $user->media()->where('media.type', 'file')->count(),
'totalEpub' => $user->media()->where('media.type', 'epub')->count(),
'_stripe' => $_stripe,
'checkSubscription' => $checkSubscription ?? null,
'media' => $media,
'mediaTitle' => $mediaTitle,
'sortPostByTypeMedia' => $sortPostByTypeMedia,
'allPayment' => $allPayment,
'paymentIncomplete' => $paymentIncomplete ?? null,
'likeCount' => $likeCount,
'categories' => $categories,
'paymentGatewaySubscription' => $paymentGatewaySubscription->payment_gateway ?? null,
'subscriptionsActive' => $subscriptionsActive,
'plans' => $plans,
'userPlanMonthlyActive' => $userPlanMonthlyActive ?? null,
'userProducts' => $userProducts,
'shopCategories' => $shopCategories ?? null,
'token_time' => $token_time
]);
}
***************************************Custom code ends
// custom code for creating promotion campaign subscription.
public function mypromotion()
{
$creator_id = auth()->user()->id;
$get_records = DB::table("promotion_campaign")->where('creator_id', $creator_id)->get();
$promotion_campaign_exist = false;
if (count($get_records) != 0) {
$promotion_campaign_exist = true;
$link = $get_records[0]->link;
return view('users.my_promotion', compact('promotion_campaign_exist', 'link'));
} else {
return view('users.my_promotion', compact('promotion_campaign_exist'));
}
}
public function trialLink(Request $request)
{
// date_default_timezone_set("USA/Chicago");
$promotion_campaign_name = $request->input("promotion_campaign_name");
$no_of_subscribers = $request->input("offer_limit");
$offer_expiry_days = $request->input("offer_expiration");
$free_trial_duration = $request->input("free_trial_duration");
$creator_id = auth()->user()->id;
$username = auth()->user()->username;
$current_time = date("Y-m-d H:i:s");
$currentDate = strtotime($current_time);
$futureDate = $currentDate + (60 * 5);
$expired_date = date("Y-m-d H:i:s", $futureDate);
$encrypted_string = encrypt($current_time);
$decrypted_string = decrypt($encrypted_string);
$link = url('/') . '/' . $username . '?token=' . $encrypted_string;
$get_records = DB::table("promotion_campaign")->where('creator_id', $creator_id)->get();
if (count($get_records) != 0) {
return response()->json(["code" => "500"]);
}
DB::table("promotion_campaign")->insert([
'creator_id' => $creator_id,
"link" => $link,
"no_of_subscribers" => $no_of_subscribers,
"offer_expiry_days" => $offer_expiry_days,
"free_trial_duration" => $free_trial_duration,
"expired_at" => $expired_date
]);
return response()->json(["code" => "501", "generated_link" => $link]);
}
public function mypromotion()
{
return view('users.my_promotion');
}
// custom code ends
looking through google and this site for the answer to help debug this code.
New contributor
lenard blanks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2