Exemplo n.º 1
0
 public function getIndex()
 {
     $market = array();
     $providers = Auth::user()->providers;
     $query = MarketItem::whereIn('provider', $providers);
     foreach ($query->get()->groupBy('post_id') as $key => $marketItem) {
         $market[$key] = (new Collection($marketItem))->keyBy('action')->sortByDesc('updated_at');
     }
     return view('home', compact('market'));
 }
Exemplo n.º 2
0
 public function postBoost(Request $request)
 {
     $post = Post::find((int) $request->input('post_id'));
     if (!$post) {
         throw new \Exception('Post not found');
     }
     foreach (config('br.actions.' . $post->provider) as $key => $value) {
         $input['provider'] = $post->provider;
         $input['user_id'] = Auth::id();
         $input['post_id'] = $post->id;
         $input['action'] = $key;
         $reward = (int) $request->input($key);
         if ($reward) {
             $item = MarketItem::firstOrCreate($input);
             $item->reward = $reward;
             $item->save();
         } else {
             $item = MarketItem::whereProvider($input['provider'])->wherePostId($input['post_id'])->whereAction($input['action'])->first();
             if ($item) {
                 $item->delete();
             }
         }
     }
 }