public function index() { $studentsCount = User::count(); $lessons = Lesson::where('published', 1)->orderBy('id', 'desc')->take(30)->get(); $available = Series::where('for_sale', 1)->where('preorder', 0)->get(); $presale = Series::where('for_sale', 1)->where('preorder', 1)->get(); //$series = Series::where('for_sale', 1)->orderBy('id')->take(10)->get(); return view('welcome', compact('studentsCount', 'available', 'presale', 'lessons')); }
public function show($slug) { $series = Series::with(['sections' => function ($query) { $query->orderBy('series_order', 'asc'); }])->where('slug', $slug)->firstOrFail(); $user_lessons = ''; if (Auth::check()) { $user_lessons = Auth::user()->lessons; } $price = $series->price / 100; return view('series.show', compact('series', 'price', 'user_lessons')); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $series = Series::find($id); $series->name = $request->name; $series->language = $request->language; $series->summary = $request->summary; $series->description = $request->description; $series->thank_you_page = $request->thank_you_page; $series->thank_you_email = $request->thank_you_email; $series->save(); $series->tag($request->tags); }
public function dashboard() { if (Auth::user()->stripe_active == 1) { $series = Series::where('published', 1)->get(); } else { $series = Auth::user()->series; } $all_series = Series::where('for_sale', 1)->orderBy('id', 'desc')->get(); $other_series = $all_series->diff($series); //dd($other_series); return view('user.dashboard', compact('series', 'other_series')); }
public function show(Request $request, $slug) { $lesson = Lesson::with('series')->where('slug', $slug)->firstOrFail(); $series = Series::with(['sections' => function ($query) { $query->orderBy('series_order', 'asc'); }])->find($lesson->section->series_id); //dd($lesson); if ($request->user() and $request->user()->series->contains($lesson->section->series_id) || $request->user()->stripe_active == 1) { $user_lessons = Auth::user()->lessons; return view('lesson.show', compact('lesson', 'series', 'user_lessons')); } else { return redirect('purchase/' . $series->slug); } return redirect('login')->withErrors('You must be logged in to view this lesson.'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $lesson = new Lesson(); $lesson->name = $request->name; $lesson->setDescriptionAttribute($request->description); $lesson->github = $request->github; $lesson->video = $request->video; $lesson->download = $request->download; $lesson->length = $request->length; $lesson->series_id = $request->series_id; $lesson->section_id = $request->section_id; $lesson->save(); $series = Series::find($lesson->series_id); $series->length = (int) $series->length + (int) $request->length; $series->lessons = $series->lessons + 1; $series->save(); return redirect('/admin/lessons/create'); }
public function stacksocial(Request $request) { if ($request['confirmed'] && $request['confirmed'] == 'purchased') { $data = ['name' => $request['purchaseName'], 'email' => $request['purchaseEmail'], 'password' => 'makerscabin']; $user = $this->create($data); //dd($user); // Assign Product to User $series = Series::find(2); $user->series()->save($series, ['payment_type' => 'stacksocial', 'amount' => '39.00']); // foreach($product->schools as $school) { // $user->schools()->save($school); // } // Assign Student Role to User // if (! $user->hasRole('student')) // $user->assignRole('student'); return view('user/stacksocial', compact('data', 'series', 'user')); } return 'https://makerscabin.com/ios/stacksocial?purchaseEmail=' . $request['purchaseEmail'] . '&purchaseName=' . urlencode($request['purchaseName']) . '&confirmed=purchased'; }
public function handlePayment(Request $request) { if (Auth::check()) { $user = Auth::user(); } else { $userSearch = User::where('email', $request->email)->first(); if (!$userSearch) { $user = User::create(['name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->email)]); Auth::login($user); if ($request->provider == 'paypal') { return redirect('repurchase/' . $request->series_id); } } else { $user = $userSearch; Auth::login($user); if ($request->provider == 'paypal') { return redirect('repurchase/' . $request->series_id); } } } $series = Series::find($request->series_id); $amount = number_format($series->price / 100, 2); switch ($request->provider) { case 'stripe': $gateway = Omnipay::create('Stripe'); $token = $request->stripeToken; $params = ['amount' => $amount, 'currency' => 'USD', 'token' => $token, 'payment_type' => 'stripe', 'receipt_email' => $user->email, 'description' => $series->name]; $gateway->setApiKey(ENV('STRIPE_SECRET')); break; case 'paypal': $gateway = Omnipay::create('PayPal_Express'); $params = ['cancelUrl' => 'https://makerscabin.com/purchase', 'returnUrl' => ENV('PAYPAL_RETURN'), 'description' => $series->name, 'amount' => $amount, 'currency' => 'USD', 'series_id' => $series->id, 'payment_type' => 'paypal']; $gateway->setUsername(ENV('PAYPAL_USERNAME')); $gateway->setPassword(ENV('PAYPAL_PASSWORD')); $gateway->setSignature(ENV('PAYPAL_SIGNATURE')); $gateway->setTestMode(ENV('PAYPAL_TEST')); Session::put('params', $params); Session::save(); DB::table('paypal_tracking')->insert(['user_id' => $user->id, 'series_id' => $series->id]); break; default: # code... break; } //$response = $gateway->purchase($params)->send(); $payment = $gateway->purchase($params); $data = $payment->getData(); $data['receipt_email'] = $user->email; $data['metadata'] = ['email' => $user->email, 'user_id' => $user->id]; $response = $payment->sendData($data); if ($response->isSuccessful()) { $user->series()->save($series, ['payment_type' => $params['payment_type'], 'amount' => $params['amount']]); $this->dispatch(new SendPurchaseConfirmationEmail($user, $series)); return redirect()->route('thanks', $series->slug)->withSuccess('Your purchase of ' . $series->name . ' was successful.'); } elseif ($response->isRedirect()) { $response->redirect(); } else { $e = $response->getMessage(); //dd($e); return redirect('purchase/' . $series->slug)->with('errorMessage', $e); } }
public function getThanks($slug) { $series = Series::where('slug', $slug)->firstOrFail(); return view('user.thanks', compact('series')); }
public function show($slug) { $theTag = DB::table('tags')->where('slug', $slug)->first(); $series = Series::whereTag($slug)->get(); return view('tag.show', compact('series', 'theTag')); }