コード例 #1
0
ファイル: Categories.php プロジェクト: erekle1/adrenalini
 public static function parents($n = 0)
 {
     if ($n > 0) {
         return Categories::where('parent', '>', '0')->get();
     }
     return Categories::where('parent', '=', '0')->get();
 }
コード例 #2
0
 public function pullCategories()
 {
     $uri = 'https://tartan.plaid.com/categories';
     $client = new Client();
     $response = $client->get($uri);
     $array = json_decode($response->getBody(), true);
     //var_dump($array['66']);
     foreach ($array as $record) {
         $category = new Categories();
         foreach ($record as $key => $value) {
             if ($key == 'id') {
                 if (Categories::where('Cat_ID', '=', $value)->exists()) {
                     break;
                 }
                 $category['Cat_ID'] = $value;
             }
             //echo "I should not be here";
             if ($key == 'type') {
                 $category['Type'] = $value;
             }
             if ($key == 'hierarchy') {
                 $category['c1'] = $value['0'];
                 isset($value['1']) ? $category['c2'] = $value['1'] : ($category['c2'] = null);
                 isset($value['2']) ? $category['c3'] = $value['2'] : ($category['c3'] = null);
             }
             $category->save();
         }
     }
     return view('categories')->with('data', $array);
 }
コード例 #3
0
 /**
  * Display the specified resource.
  *
  * @param  string  $name
  * @return Response
  */
 public function show($name)
 {
     $category = Categories::where('name', $name)->first();
     if (!$category) {
         return redirect()->action('CategoriesController@index');
     }
     $pageDescription = 'Category: ' . $name;
     $articles = $category->articles()->simplePaginate(Articles::itemsPerPage);
     return view('articles.index', compact('articles', 'pageDescription'));
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: calimanleontin/bet
 public function user_posts_all(Request $request)
 {
     //
     $user = $request->user();
     $posts = Posts::where('author_id', $user->id)->orderBy('created_at', 'desc')->paginate(5);
     $title = $user->name;
     $id = $request->user()->id;
     $categories = Categories::where('author_id', $id);
     return view('home')->withPosts($posts)->withTitle($title)->withTitlecategory('Categories')->withCategories($categories);
 }
コード例 #5
0
 public function show($slug)
 {
     /**
      * @var $category Categories
      */
     $category = Categories::where('slug', $slug)->first();
     if ($category == NULL) {
         return redirect('/')->withErrors('Requested url does not exist');
     }
     $categories = Categories::all();
     /**
      * @var $products Products
      */
     $products = $category->products()->paginate(9);
     return view('home')->withProducts($products)->withCategories($categories)->withTitle('Products from the  category ' . $category->title);
 }
コード例 #6
0
 public function index($id = 0)
 {
     //get rundom category
     if ($id == 0) {
         $category = Categories::where('parent_id', '!=', 0)->orderBy(DB::raw('RAND()'))->take(1)->get();
         $id = $category[0]->id;
     }
     //get all categories for menu
     $categories = Categories::all();
     $categories = $categories->sortBy('sort_id');
     //get categories for slider
     $sliders = Categories::where('parent_id', '!=', 0)->orderBy(DB::raw('RAND()'))->take(3)->get();
     //get items
     $items = Items::where('categories_id', '=', $id)->get();
     $data = ['categories' => $categories, 'items' => $items, 'id' => $id, 'sliders' => $sliders];
     return view('categories.index', $data);
 }
コード例 #7
0
 public function updateCategoryPost()
 {
     $categories = Categories::where('added_by', Session::get('id'))->get();
     $data = Input::get('enabled');
     foreach ($categories as $category) {
         if (in_array($category->id, $data)) {
             $category->is_enabled = "yes";
             $category->save();
         } else {
             $category->is_enabled = "no";
             $category->save();
         }
     }
     Flash::success('Category preferences updated successfully.');
     return redirect('/admin/categories/manage');
 }
コード例 #8
0
ファイル: PostController.php プロジェクト: calimanleontin/bet
 public function search(Request $request)
 {
     $q = $request->get('q');
     $categories = Categories::where('title', 'LIKE', '%' . $q . '%')->get();
     $posts = Posts::where('title', 'LIKE', '%' . $q . '%')->where('active', 1)->orderBy('created_at', 'desc')->paginate(5);
     $titlecategory = 'Categories you searched for';
     $titlepost = 'Articles you searched for';
     //		var_dump($categories->first()->title);
     //		die();
     return view('home')->withPosts($posts)->withTitlepost($titlepost)->withTitlecategory($titlecategory)->withCategories($categories);
 }
コード例 #9
0
 public function renderMenu()
 {
     $categories = Categories::where('is_publish', '1')->get()->toArray();
     // Render View With Parameters
     return \View::make('include.menu')->with('categories', $categories);
 }
コード例 #10
0
 /**
  * Insère un nouvel item dans la BDD
  *
  * @param Request $request
  * @return bool|mixed
  */
 public function create(Request $request)
 {
     $datas = $request->all();
     $manager = new ImageManager(['driver' => 'imagick']);
     // Création de l'Item
     $item = new Items();
     $item->user_id = Auth::user()->id;
     $item->category_id = Categories::where('slug', $datas['category'])->value('id');
     $item->name = trim($datas['name']);
     $item->description = trim($datas['description']);
     $item->price = $datas['price'];
     $item->date_start = $datas['date_start'];
     $item->date_end = $datas['date_end'];
     // Récupération de la photo envoyée par l'utilisateur
     $file = $request->file('photo');
     $filename = str_limit(str_replace(['/', '\\'], '', $file->getClientOriginalName()), 30) . str_random();
     $filename_thumb = $filename . '_thumb';
     // Sauvegarde de la photo
     $file->move(public_path('upload'), $filename . '.' . $file->getClientOriginalExtension());
     // On sauvegarde un lien relatif pour le lien de la photo, pour éviter un bordel monstre lors d'un
     // changement de nom de domaine.
     $item->photo = 'upload/' . $filename . '.jpg';
     // Là on peut utiliser le chemin absolu de l'image (/home/..../image.jpg)
     $filename = public_path('upload') . '/' . $filename;
     $filename_thumb = public_path('upload') . '/' . $filename_thumb;
     // Active l'entrelacement sur la photo envoyée par l'utilisateur et réduit la qualité
     $manager->make($filename . '.' . $file->getClientOriginalExtension())->interlace(true)->save($filename . '.jpg', 80);
     // Si par exemple l'utilisateur a envoyé un .png (ou un .JpG), alors on supprime l'image,
     // puisqu'on a déjà sauvegardé une version en .jpg
     if ($file->getClientOriginalExtension() !== 'jpg') {
         unlink($filename . '.' . $file->getClientOriginalExtension());
     }
     // Création de la miniature, de taille 300px * ratio px.
     $manager->make($filename . '.jpg')->resize(300, null, function ($constraint) {
         $constraint->aspectRatio();
     })->interlace(true)->save($filename_thumb . '.jpg');
     // Si on a bien réussi à sauvegarder l'Item, on renvoie l'id, pour une redirection sur la page de l'Item
     if ($item->save()) {
         return $item->id;
     }
     // Sinon il y a eu un problème. :< :< :<
     return false;
 }
コード例 #11
0
 public function types(Request $request)
 {
     $users = Users::where('id', Session::get('id'))->first();
     $category = Categories::where('id', base64_decode($request->category))->where('added_by', $users->added_by)->where('is_enabled', "yes")->first();
     return view("pages.user.types", ["category" => $category]);
 }
コード例 #12
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $categories = Categories::where('creater_id', Auth::id())->orderBy('id', 'desc')->get();
     return view('category.index')->with('categories', $categories);
 }
コード例 #13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $category = Categories::where('id', $id);
     $category->delete();
     return redirect('/')->withMessage('Category deleted successfully');
 }
コード例 #14
0
 public function update(Request $request)
 {
     $user = $request->user();
     $id = $request->input('id');
     $product = Products::where('id', $id)->first();
     if ($user->id != $product->author_id and $user->is_admin() == false and $user->is_moderator() == false) {
         return redirect('/')->witheErrors('You have not sufficient permissions ');
     }
     $name = $request->input('name');
     $quantity = $request->input('quantity');
     $description = $request->input('description');
     $image = Input::file('image');
     $categories = $request->input('category');
     $duplicate = Products::where('name', $name)->first();
     if ($duplicate != null and $duplicate->id != $product->id) {
         return redirect('/edit/product' . $product->id)->withErrors('The name is already in use');
     }
     if ($quantity != null) {
         $product->quantity = $quantity;
     }
     if ($description != null) {
         $product->description = $description;
     }
     if ($image != null) {
         $destinationPath = 'images/catalog';
         // upload path
         $extension = Input::file('image')->getClientOriginalExtension();
         $fileName = rand(11111, 99999) . '.' . $extension;
         $product->image = $fileName;
         Input::file('image')->move($destinationPath, $fileName);
     }
     if ($categories != null) {
         $product->categories()->detach();
         foreach ($categories as $category) {
             $category = Categories::where('title', $category)->first();
             $product->categories()->attach($category->id);
         }
     }
     $product->save();
     return redirect('/product/' . $product->slug)->withMessage('Product updated successfully');
 }