public function getEdit($id)
 {
     $category = Category::select('id', 'name', 'prarent_id')->get()->toArray();
     $product = Product::findOrFail($id);
     $product_img = Product::findOrFail($id)->pimages()->get()->toArray();
     return view('backend.product.edit', compact('category', 'product', 'product_img'));
 }
Example #2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $users = User::select('id')->get();
     $products = Product::select('id')->get();
     $categories = Category::select('id')->get();
     $areas = Area::select('id')->get();
     $orders = Order::select('id')->get();
     return view('admin.dashboard', compact('users', 'products', 'categories', 'areas', 'orders'));
 }
Example #3
0
    public function getViewCat($category_id)
    {
       // $posts = DB::table('posts')
       //     ->where('category_id', '=', $category_id)
        //    ->get();

        return view('category')
        ->with('title', 'Blog | Category')
        ->with('catdescription',Category::select('description')->where('id', $category_id)->first())
        ->with('posts', Post::where('category_id', '=', $category_id)->paginate(10))
        ->with('category', Category::all());
    }
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $user = Auth::user();
     $user_type = $user->user_type;
     if ($user_type == 'COMPANY') {
         $id_company = $user->id_company;
     } else {
         $id_company = Session::get('id_company');
     }
     $categories = Category::select('category_name', 'id_category')->where('id_company', '=', $id_company)->get();
     $products = Product::where('id_company', '=', $id_company)->get();
     return view("pedidos.novo", compact('products', 'categories'));
 }
 /**
  * Отображаем пагинацией все новости в конкретной категории
  *
  * @param $id
  * @return \Illuminate\View\View
  */
 public function categoryId($id)
 {
     try {
         $data = \DB::table('news')->where('category_id', $id)->where('publish', '1')->orderBy('id', 'desc')->paginate(10);
         $categoryTitle = Category::select('title')->where('id', $id)->where('publish', 1)->get()[0]->title;
     } catch (\ErrorException $e) {
         abort(404);
     }
     // обрезаем 200 символов текста новости
     $this->get200Text($data);
     $this->title .= ': ' . $categoryTitle . $this->getTitlePagination();
     return view('news.list', ['title' => $this->title, 'data' => $data, 'categoryTitle' => $categoryTitle]);
 }
 /**
  * Отображаем пагинацией все статьи в конкретной категории
  *
  * @param $id
  * @return \Illuminate\View\View
  */
 public function categoryId($id)
 {
     // почему-то не работает upd:заработало. спасибо stackoverflow!
     //$data = Category::find($id)->articles()->where('publish', '1')->paginate(5);
     try {
         $data = \DB::table('info')->where('category_id', $id)->where('publish', '1')->where('published_at', '<=', Carbon::now())->orderBy('id', 'desc')->select('title', 'url')->paginate(10);
         $categoryTitle = Category::select('title')->where('id', $id)->where('publish', 1)->get()[0]->title;
     } catch (\ErrorException $e) {
         abort(404);
     }
     $this->title .= $categoryTitle . $this->getTitlePagination();
     return view('articles.list', ['title' => $this->title, 'data' => $data, 'categoryTitle' => $categoryTitle]);
 }
Example #7
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $table = "company";
     if (\Schema::hasTable($table)) {
         $main_company = Company::find(1)->toArray();
         $categories_menu = \Cache::remember('categories_mothers', 25, function () {
             return Category::select('id', 'name')->childsOf('mothers')->actives()->get()->toArray();
         });
         $menu = [];
         foreach ($categories_menu as $value) {
             $menu[$value['id']] = $value;
         }
         \View::share('main_company', $main_company);
         \View::share('categories_menu', $menu);
     }
 }
Example #8
0
 protected function tree($item, $sort = 'ASC')
 {
     $collector = [];
     $level = 1;
     if ($item->parent_id > 0) {
         $parent = Category::select('id', 'name', 'description', 'slug', 'parent_id')->where('id', $item->parent_id)->get();
         $collector[] = ['level' => $level, 'id' => $parent[0]->id, 'name' => $parent[0]->name, 'description' => $parent[0]->description, 'slug' => $parent[0]->slug, 'parent_id' => $parent[0]->parent_id];
         ++$level;
         while ($parent[0]->parent_id > 0) {
             $parentAux = Category::select('id', 'name', 'description', 'slug', 'parent_id')->where('id', $parent[0]->parent_id)->get();
             $parent[0]->parent_id = $parentAux[0]->parent_id;
             $collector[] = ['level' => $level, 'id' => $parentAux[0]->id, 'name' => $parentAux[0]->name, 'description' => $parentAux[0]->description, 'slug' => $parentAux[0]->slug, 'parent_id' => $parentAux[0]->parent_id];
             ++$level;
         }
     }
     if ($sort === 'DESC' || $sort === 'desc') {
         rsort($collector);
     }
     return $collector;
 }
 public function getall()
 {
     $categories = Category::select('id', 'cat_name', 'img_url', 'cat_position')->get();
     return Response::json($categories);
 }
 /**
  * @param Category $except
  *
  * @return CategoriesController
  */
 protected function getCategoryOptions($except = null)
 {
     /** @var \Kalnoy\Nestedset\QueryBuilder $query */
     $query = Category::select('id', 'name')->withDepth();
     if ($except) {
         $query->whereNotDescendantOf($except)->where('id', '<>', $except->id);
     }
     return $this->makeOptions($query->get());
 }
 public static function getRandId()
 {
     $category = Category::select(['id'])->orderByRaw('RAND()')->take(1)->first();
     return $category->id;
 }
 /**
  * @param Category $except
  *
  * @return CategoriesController
  */
 protected function getCategoryOptions($except = null)
 {
     $query = Category::select('id', 'name')->withDepth();
     if ($except) {
         $query->whereNotDescendantOf($except)->where('id', '<>', $except->id);
     }
     return $this->makeOptions($query->get());
 }
 public function propertyCategories()
 {
     $search = \Input::get('q');
     if ($search) {
         $categories = \App\Category::select('Categories.*')->join('CategoryLanguages', 'CategoryLanguages.property_id', '=', 'Categories.id')->where('CategoryLanguages.locale', $this->lang)->where('CategoryLanguages.title', 'like', $search . '%')->orderBy('Categories.created_at', 'desc')->paginate($this->limit);
     } else {
         $categories = \App\Category::orderBy('order', 'asc')->paginate($this->limit);
     }
     return view('admin.pages.categories', compact('categories'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($slug)
 {
     return view('admin.articles.edit', ['article' => Article::with('tags', 'category')->where('slug', $slug)->firstOrFail(), 'categories' => Category::select('id', 'name')->get(), 'tags' => Tag::select('id', 'name')->get()]);
 }
 public function getEdit($id)
 {
     $data = Category::findOrFail($id)->toArray();
     $parent = Category::select('id', 'name', 'prarent_id')->get()->toArray();
     return view('backend.category.edit', compact('parent', 'data'));
 }
Example #16
0
 /**
  * parentsTree
  * Retrieve all the categories parents of one passed through parameter,
  * checking data from bottom to top
  * @param [int] $id is the id category evaluated
  * @param [array] $array is the array to be used out of the model
  * @param [array] $fields is the array that contais the table field we want to retrieve
  */
 public static function parentsTree($id, &$array, $fields = ['id', 'category_id', 'name'])
 {
     $categories = Category::select($fields)->where('id', $id)->get()->toArray();
     if (is_null($categories)) {
         return;
     }
     foreach ($categories as $value) {
         $array[] = $value;
         Category::parentsTree($value['category_id'], $array, $fields);
     }
     return;
 }
 /**
  * [Search products in auto complete fields].
  *
  * @param Request $request [Request laravel]
  *
  * @return [type] [json array]
  */
 public function searchAll(Request $request)
 {
     $crit = $request->get('crit');
     $suggest = $request->get('suggest');
     $group = $request->get('group');
     $response['products'] = ['results' => null, 'suggestions' => null];
     $crit = str_replace(' ', '%', trim($crit));
     $crit = str_replace('%%', '%', $crit);
     if ($crit != '') {
         if ($suggest) {
             $response['products']['categories'] = Category::select('id', 'name')->search($crit, null, true)->actives()->where('type', 'store')->orderBy('name')->take(3)->get();
         }
         $response['products']['results'] = Product::where(function ($query) use($crit) {
             $query->where('name', 'like', '%' . $crit . '%')->orWhere('description', 'like', '%' . $crit . '%');
         })->select('id', 'name', 'products_group')->actives()->free()->orderBy('rate_val', 'desc');
         if ($group) {
             $response['products']['results']->where(function ($query) use($group) {
                 $query->where('products_group', '<>', $group)->orWhereNull('products_group');
             })->where('id', '<>', $group);
         }
         $response['products']['results'] = $response['products']['results']->take(5)->get();
         $deep = '';
         if ($suggest) {
             $crit = str_replace('%', '', $crit);
             for ($i = 0; $i < strlen($crit); $i++) {
                 $deep .= ' ' . $crit[$i];
             }
         }
         if (!$response['products']['results']->count() && strlen($crit) > 2) {
             $response['products']['results'] = Product::select('id', 'name', 'products_group')->search($deep, null, true)->actives()->free()->orderBy('rate_val', 'desc');
             if ($group) {
                 $response['products']['results']->where(function ($query) use($group) {
                     $query->where('products_group', '<>', $group)->orWhereNull('products_group');
                 })->where('id', '<>', $group);
             }
             $response['products']['results'] = $response['products']['results']->take(5)->get();
         }
         if ($suggest) {
             $response['products']['suggestions'] = self::getSuggestions(['user_id' => \Auth::id(), 'preferences_key' => 'my_searches', 'limit' => 3, 'select' => ['id', 'name', 'features']]);
             if (!$response['products']['categories']->count() && strlen($crit) > 2) {
                 $response['products']['categories'] = Category::select('id', 'name')->search($deep, null, true)->actives()->where('type', 'store')->orderBy('name')->take(3)->get();
             }
         }
     }
     $response['products']['categories_title'] = trans('globals.suggested_categories');
     $response['products']['suggestions_title'] = trans('globals.suggested_products');
     $response['products']['results_title'] = trans('globals.searchResults');
     if ($request->wantsJson()) {
         return json_encode($response);
     } else {
         if (env('APP_DEBUG', false)) {
             dd($response);
         }
     }
 }
 /**
  * Return categories's data in a way that can be read by Datatables
  *
  * @return Response
  */
 public function getDatatable()
 {
     $categories = Category::select();
     $datatables = \Datatables::of($categories)->addColumn('deleted_at', function ($category) {
         return $category->deleted_at == null ? '<span class="label label-sm label-success">Active</span>' : '<span class="label label-sm label-danger">Deleted</span>';
     })->addColumn('created_at', function ($category) {
         return date('F j, Y, g:i a', strtotime($category->created_at));
     })->addColumn('updated_at', function ($category) {
         return date('F j, Y, g:i a', strtotime($category->created_at));
     })->addColumn('actions', function ($category) {
         return '<a href="' . url('admin/categories/' . $category->id . '/edit') . '" class="btn btn-success btn-sm" ><span class="glyphicon glyphicon-pencil"></span>  Edit</a>';
     });
     $filters = \Input::get('filters');
     if (!empty($filters)) {
         $datatables->filter(function ($query) use($filters) {
             foreach ($filters as $fName => $fValue) {
                 if (!$fValue) {
                     continue;
                 }
                 switch ($fName) {
                     case 'id':
                         $query->where('category.id', '=', $fValue);
                         break;
                     case 'name':
                     case 'slug':
                     case 'description':
                         $query->where('slug', 'LIKE', '%' . $fValue . '%');
                         break;
                     case 'created_at_from':
                         $query->where('created_at', '>=', $fValue);
                         break;
                     case 'created_at_to':
                         $query->where('created_at', '<=', $fValue);
                         break;
                     case 'updated_at_from':
                         $query->where('updated_at', '>=', $fValue);
                         break;
                     case 'updated_at_to':
                         $query->where('updated_at', '<=', $fValue);
                         break;
                     case 'deleted':
                         if ($fValue) {
                             if ($fValue == 1) {
                                 $query->whereNull('deleted_at');
                             }
                             if ($fValue == -1) {
                                 $query->where('deleted_at', '!=', 'null');
                             }
                         }
                         break;
                 }
             }
         });
     }
     return $datatables->make(true);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($id)
 {
     $categories = Category::select(array('id', 'name', 'created_at'))->where('department', '=', $id);
     return \Datatables::of($categories)->addColumn('actions', '<a class="btn btn-xs btn-alt" data-toggle="modal" onClick="launchUpdateCategoryModal({{$id}});" data-target=".modalEditCategory">Edit</a>')->make(true);
 }