/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $offers = Offer::where('status', '=', 1)->take(5)->get(); $this->data['offers'] = $offers; $products = Product::where('status', '=', 1)->get(); foreach ($products as $product) { $rank = $product->rank()->first(); if (count($rank)) { array_set($product, 'rank', $rank->rank); } $image = $product->images()->first(); array_set($product, 'image', $image['file']); } $this->data['products'] = $products; $brochures = Brochure::where('status', '=', 1)->get(); $count = 0; foreach ($brochures as $brochure) { $rank = $brochure->rank()->first(); if (count($rank)) { array_set($brochure, 'rank', $rank->rank); $count++; } if ($count == 4) { break; } } $this->data['brochures'] = $brochures; $data = $this->data; return view('index', $data); }
public function postDelete(Request $request, $id) { $offer = Offer::where('id', $id)->first(); if ($offer != null) { $offer->delete(); $msg = "Предложение \"" . $offer->title . "\" удалено."; return redirect('admin/offer')->with('msg', $msg); } else { $msg = "Предложения с id = " . $id . " не существует."; return redirect('admin/offer')->with('msg', $msg); } }
/** * Show the application dashboard to the user. * * @return Response */ public function dashboard() { $user = User::find(Auth::user()->id); $communitys = Community::all()->lists('name', 'id'); $feedbacksGiven = Feedback::where('giver_id', Auth::user()->id)->get(); $feedbacks = Feedback::where('receiver_id', Auth::user()->id)->get(); $activePosts = Post::where('user_id', Auth::user()->id)->where('sold', null)->get(); $offers = Offer::where('post_creator', Auth::user()->id)->whereHas('post', function ($q) { $q->where('sold', NULL); })->orderBy('created_at', 'desc')->get(); return view('pages.dashboard', ['user' => $user, 'communities' => $communitys, 'offers' => $offers, 'feedbacks' => $feedbacks, 'activePosts' => $activePosts, 'feedbacksGiven' => $feedbacksGiven]); }
/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { if (Auth::check()) { $offers = Offer::where('post_creator', Auth::user()->id)->whereHas('post', function ($q) { $q->where('sold', NULL); })->orderBy('created_at', 'desc')->count(); } else { $offers = ""; } $categories = Category::all(); $view->with(['categories' => $categories, 'offers' => $offers]); }
public function index() { // This view changes dependin on the type of user $user_id = Auth::user()->id; $user_type = Auth::user()->getOriginal('user_type'); if ($user_type == 'cus') { $offers = Offer::where('user_id', $user_id)->get(); } else { $offers = Offer::all(); } $total = count($offers); return view('offer.index', compact('offers', 'total')); }
public function getOffers(Request $request) { if ($request->input('id') == null) { $offers = Offer::all(); return view('home.offers')->with('offers', $offers); } else { $offer = Offer::where('id', $request->input('id'))->first(); if ($offer == null) { return redirect('offers'); } return view('home.offer')->with('offer', $offer); } }
/** * Display the specified resource. * * @param $slug * @return Response */ public function show($slug) { $offer = Offer::where('slug', $slug)->first(); return view('account.offers.show', compact('offer')); }
/** * Remove current offer used on sign up. */ public function test_it_remove_as_sign_up_offer() { // Generate new offer $generatedOffer = factory(App\Offer::class)->create(['use_on_sign_up' => true]); // Remove as sign up offer $offer = Offer::find($generatedOffer->id); $offer->use_on_sign_up = false; $offer->save(); // Check if offer is no more used on sign up $this->seeInDatabase('offers', ['id' => $offer->id, 'paymill_offer_id' => $offer->paymill_offer_id, 'use_on_sign_up' => false]); // Make sure no other offer is used on sign up $this->assertEquals(0, Offer::where('use_on_sign_up')->count()); }
/** * Use offer on sign up. * * @param $offerId * @param UseOfferOnSignUpRequest $request * @return mixed */ public function useOfferOnSignUp($offerId, UseOfferOnSignUpRequest $request) { $response = new AjaxResponse(); $offer = Offer::where('id', $offerId)->first(); // Make sure offer exists if (!$offer) { $response->setFailMessage(trans('offers.offer_not_found')); return response($response->get(), 404)->header('Content-Type', 'application/json'); } // Remove other offer used on sign up Offer::where('use_on_sign_up', true)->update(['use_on_sign_up' => false]); // Update current offer to be used on sign up $offer->use_on_sign_up = true; $offer->save(); // Return json response $response->setSuccessMessage(trans('offers.this_offer_is_used_on_sign_up')); $response->addExtraFields(['offer' => Offer::countAssociatedSubscriptions()->where('offers.id', $offerId)->first()]); return response($response->get())->header('Content-Type', 'application/json'); }
/** * Register any application authentication / authorization services. * * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return void */ public function boot(GateContract $gate) { $this->registerPolicies($gate); // USERS $gate->define('see-email', function ($user, $profile) { if ($user->id == $profile->id or $user->id == 1) { return true; } else { return false; } }); // VIOLATIONS // Create (only Customers) $gate->define('create-violation', function ($user) { return $user->getOriginal('user_type') == 'cus'; }); // Edit (only Author) $gate->define('edit-violation', function ($user, $violation) { return $violation->user_id == $user->id; }); // Delete (only Author) $gate->define('delete-violation', function ($user, $violation) { return $violation->user_id == $user->id; }); // OFFERS $gate->define('see-offers', function ($user) { return $user->getOriginal('user_type') == 'pro'; }); // Create (only Pros) $gate->define('create-offer', function ($user) { return $user->getOriginal('user_type') == 'pro'; }); // Edit (only Author) $gate->define('edit-offer', function ($user, $offer) { if ($offer->author->id == $user->id and $offer->getOriginal('status') < 1) { return true; } else { return false; } }); // Delete (only Author) $gate->define('delete-offer', function ($user, $offer) { if ($offer->author->id == $user->id and $offer->getOriginal('status') < 1) { return true; } return false; }); // Full view (only author of Violation and author of Offer) $gate->define('full-view-offer', function ($user, $offer) { if ($offer->author->id == $user->id or $offer->violation->author->id == $user->id) { return true; } else { return false; } }); // Send offer (only Pros) $gate->define('send-offer', function ($user, $violation) { $offers = \App\Offer::where(['violation_id' => $violation->id, 'pro_id' => $user->id])->get(); if (count($offers)) { return false; } else { return true; } }); // Award Offer (only Customers) $gate->define('award-offer', function ($user, $offer) { if ($offer->violation->user_id == $user->id and $offer->getOriginal('status') == 0 and $offer->violation->getOriginal('status') == 0) { return true; } else { return false; } }); // Remove Award offer (only customer) $gate->define('remove-award', function ($user, $offer) { if ($offer->violation->author->id == $user->id and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 3) { return true; } else { return false; } }); // Submit comments $gate->define('add-comment', function ($user, $offer) { if ($user->id == $offer->violation->user_id or $user->id == $offer->author->id) { return true; } else { return false; } }); // Submit conditions $gate->define('submit-conditions', function ($user, $offer) { if ($user->id == $offer->author->id and count($offer->conditions) > 0 and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 2) { return true; } else { return false; } }); // Add new condition $gate->define('add-condition', function ($user, $offer) { if ($user->id == $offer->author->id and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 3) { return true; } else { return false; } }); // Delete condition $gate->define('delete-condition', function ($user, $condition) { $offer = $condition->offer; if ($user->id == $offer->author->id and $user->id == $condition->author->id and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 3) { return true; } else { return false; } }); // Accept Offer Conditions $gate->define('accept-conditions', function ($user, $offer) { if ($user->id == $offer->violation->author->id and $offer->getOriginal('status') == 2) { return true; } else { return false; } }); // Pay Offer $gate->define('pay-offer', function ($user, $offer) { if ($user->id == $offer->violation->author->id and $offer->getOriginal('status') == 3 and !$offer->paid) { return true; } else { return false; } }); // Can compelte order $gate->define('complete-offer', function ($user, $offer) { if ($user->id == $offer->author->id and $offer->getOriginal('status') == 4) { return true; } else { return false; } }); // Can close the offer $gate->define('close-offer', function ($user, $offer) { if ($user->id == $offer->violation->author->id and $offer->getOriginal('status') == 5) { return true; } else { return false; } }); }