Example #1
0
 public function show($tag)
 {
     $rs = Tag::where('tag', $tag)->get();
     $arr = array();
     foreach ($rs as $v) {
         array_push($arr, $v->article_id);
     }
     $articles = Article::whereIn('id', $arr)->get();
     $tags = Tag::select('tag')->distinct()->get();
     return view('member.tags.show', compact('tag', 'tags', 'articles'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function getArticles($id, $number)
 {
     $category = Category::whereName($id)->first();
     $sources = $category->sources;
     $ids = [];
     foreach ($sources as $source) {
         $ids[] = $source->id;
     }
     $articles = Article::whereIn('source_id', $ids)->orderBy('date', 'DESC')->paginate($number);
     return ['name' => $category->name, 'id' => $category->id, 'image_url' => $category->image_url, 'articles' => $articles->toArray()];
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $usr = Practicante::where('email', '=', $request->user()->email)->get();
     $actual_rank = Tag::where('name', Config::get('constants.ranks')[$usr[0]->actual_rank])->get()[0]->id;
     $withTags = DB::table('article_tag')->where('tag_id', $actual_rank)->get(array('article_id'));
     //Cleaning the array
     $justTags = array();
     foreach ($withTags as $key => $value) {
         array_push($justTags, $value->article_id);
     }
     $articles = Article::whereIn('id', $justTags)->get();
     return View('practicante.tecnicas.index')->with('articles', $articles)->with('actual_rank', $usr[0]->actual_rank)->with('ranks', Config::get('constants.ranks'));
 }
 public function articlesTag($tag)
 {
     $withTags = DB::table('article_tag')->where('tag_id', $tag)->get(array('article_id'));
     //Cleaning the array
     $justTags = array();
     foreach ($withTags as $key => $value) {
         array_push($justTags, $value->article_id);
     }
     $articles = Article::whereIn('id', $justTags)->get();
     if (count($articles) == 0) {
         return response()->json(['error' => ['message' => 'No existen articulos con esta etiqueta']], 404);
     }
     return response()->json($articles, 200);
 }
Example #5
0
 public function checkout(Request $request)
 {
     if (isset($_COOKIE['basket'])) {
         $entries = $_COOKIE['basket'];
         $entries = json_decode($entries);
     } else {
         return redirect('/');
     }
     $ids = array_pluck($entries, 'article_id');
     $items = Article::whereIn('id', $ids)->get();
     //->toArray();
     $items = $items->keyBy('id');
     $order = Order::create(['name' => $request->name, 'address' => $request->address, 'phone' => $request->phone]);
     $summary = [];
     $total_cost = 0;
     foreach ($entries as $entry) {
         OrdersToArticles::create(['article_id' => $entry->article_id, 'order_id' => $order->id, 'price' => $items->get($entry->article_id)->price, 'quantity' => $entry->amount]);
         $summary[] = ['article_id' => $entry->article_id, 'title' => $items->get($entry->article_id)->title, 'price' => $items->get($entry->article_id)->price, 'amount' => $entry->amount];
         $total_cost += end($summary)['price'] * end($summary)['amount'];
     }
     setcookie('basket', '', 0, '/');
     //удаляем куки
     return view('finish_order', ['order' => $order, 'entries' => $summary, 'total' => $total_cost]);
 }
Example #6
0
 public function deleteArticle()
 {
     $articles = Input::get('formarr', array());
     Articlecontent::whereIn('article_id', $articles)->delete();
     foreach ($articles as $article) {
         Article::find($article)->menu_relations()->detach();
     }
     Article::whereIn('id', $articles)->delete();
     return 1;
 }
Example #7
0
 /**
  * Return the favorites of a certain model or table, leave the data as is under $model->settings['favorites']
  *
  * @param $model
  * @param $data
  *
  * @return object|false
  */
 static function getFavoritesByModel($model, $data)
 {
     if (!isset($data[$model])) {
         return false;
     }
     $data = array_keys($data[$model]);
     switch ($model) {
         case 'articles':
             return Article::whereIn('id', $data)->get();
         case 'sites':
             return Site::whereIn('id', $data)->get();
         case 'professions':
             return Profession::whereIn('id', $data)->get();
         case 'classifieds':
             return Classified::whereIn('id', $data)->get();
         case 'albums':
             return Album::whereIn('id', $data)->get();
         case 'agoda':
             return AgodaHotel::whereIn('hotel_id', $data)->get();
         default:
             return false;
     }
 }
Example #8
0
 /**
  * batch update
  * @param string $act
  * @return json
  */
 public function postBatch($act = 'update')
 {
     $result = false;
     $ids = \Request::input('ids');
     $idsArr = explode(',', $ids);
     switch ($act) {
         case 'delete':
             $result = Article::whereIn('id', $idsArr)->delete();
             break;
         case 'update':
             $key = \Request::input('key');
             $value = \Request::input('value');
             $tempData = $this->parseKey($key, $value);
             $result = Article::whereIn('id', $idsArr)->update($tempData);
             break;
     }
     $msg = [];
     if ($result) {
         $msg['status'] = 'success';
     } else {
         $msg['status'] = 'failed';
     }
     return response(json_encode($msg))->header('Content-Type', 'application/json');
 }