Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

solaceng's avatar

Restructuring url to search engine friendly url

My website has its url like this

https://example.com/search?subsubcategory=smart-watches

But I want something like this

https://example.com/smart-watches

Please can someone help me on how to create view and route that will display my categories, sub categories and subsubcategories products like this. It is an ecommerce website

0 likes
21 replies
Tray2's avatar

The route could look something like this

Route::get('/products/{category}', 'ProductsController@index');

The controller method

public function index($catagory)
{
    $products = Product::where('category', $categoty)->get();
    return view('products.index')->with(['products' => $products);
}

The view

@foreach($products as $product)
    {{ $product->name }}
@endforeach
solaceng's avatar

Where to place the controller.

Inside ProductController or CategoryController?

Tray2's avatar

/App/Http/Controllers/ProductsController

Tray2's avatar

What does not work and what does your code and database structure look like?

solaceng's avatar

This is the existing CategoryController

solaceng's avatar

Do you need the existing ProductController?

Tray2's avatar

The routes file the migration the products controller.

solaceng's avatar

Where to get the expected Migration file?

Tray2's avatar

No code == No possibility to help.

Use three "```" to wrap your code segments.

//Code here
solaceng's avatar

Complete ProductController


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;
use App\Category;
use App\Language;
use App\State;
use App\BusinessSetting;
use Auth;
use App\SubSubCategory;
use Session;
use ImageOptimizer;

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function admin_products()
    {
        $type = 'In House';
        $products = Product::where('digital', '0')->where('added_by', 'admin')->orderBy('created_at', 'desc')->get();
        return view('products.index', compact('products','type'));
    }
    

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function seller_products()
    {
        $type = 'Seller';
        $products = Product::where('digital', '0')->where('added_by', 'seller')->orderBy('created_at', 'desc')->get();
        return view('products.index', compact('products','type'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $categories = Category::all();
        return view('products.create', compact('categories'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //dd($request->all());
        $product = new Product;
        $product->name = $request->name;
        $product->sub_name = $request->sub_name;
        $product->added_by = $request->added_by;
        $product->user_id = Auth::user()->id;
        $product->category_id = $request->category_id;
        $product->subcategory_id = $request->subcategory_id;
        $product->subsubcategory_id = $request->subsubcategory_id;
        $product->brand_id = $request->brand_id;
        $product->state_id = json_encode($request->states);

        if ($request->product_type == 'internal') {
            $product->product_type =  $request->product_type;
            $product->available =  $request->shipping_type;
            $product->state_id =  $request->current_state;
            $shipment_details = array();
            foreach ($request->states as $key => $i) {
                $it['state_id'] = $i;
                $it['min_num_of_day'] = $request['min_num_of_day_'.$i];
                $it['max_num_of_day'] = $request['max_num_of_day_'.$i];
                array_push($shipment_details, $it);
            }
            $product->shipment_variation = json_encode($shipment_details);
            // dd($product->shipment_variation);
        }
        elseif ($request->product_type == 'external') {
            $product->product_type =  $request->product_type;
            $product->available =  'external';
            $shipment_details = array();
                $it['min_num_of_day'] = $request['min_num_of_day_'];
                $it['max_num_of_day'] = $request['max_num_of_day_'];
                array_push($shipment_details, $it);
            $product->shipment_variation = json_encode($shipment_details);
        }

        if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
            $product->num_of_sale = rand(25,50);
        }
        elseif (Auth::user()->user_type == 'seller' && Auth::user()->seller->verification_status == '1') {
            $product->num_of_sale = rand(15,50);
        }
        if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
            $product->rating = rand(1,4);
        }
        elseif (Auth::user()->user_type == 'seller' && Auth::user()->seller->verification_status == '1') {
            $product->rating = rand(1,2);
        }
        
        if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
            $product->product_code = rand(100000,999999);
        }
        elseif (Auth::user()->user_type == 'seller' && Auth::user()->seller->verification_status == '1') {
            $product->product_code = rand(100000,999990);
        }

        $photos = array();

        if($request->hasFile('photos')){
            foreach ($request->photos as $key => $photo) {
                $path = $photo->store('uploads/products/photos');
                array_push($photos, $path);
                if($key == 0){
                    $product->meta_img = $path;
                }
                //ImageOptimizer::optimize(base_path('public/').$path);
            }
            $product->photos = json_encode($photos);
        }

        if($request->hasFile('thumbnail_img')){
            $product->thumbnail_img = $request->thumbnail_img->store('uploads/products/thumbnail');
            //ImageOptimizer::optimize(base_path('public/').$product->thumbnail_img);
        }

        if($request->hasFile('featured_img')){
            $product->featured_img = $request->featured_img->store('uploads/products/featured');
            //ImageOptimizer::optimize(base_path('public/').$product->featured_img);
        }

        if($request->hasFile('flash_deal_img')){
            $product->flash_deal_img = $request->flash_deal_img->store('uploads/products/flash_deal');
            //ImageOptimizer::optimize(base_path('public/').$product->flash_deal_img);
        }

        $product->unit = $request->unit;
        $product->link_s = $request->link_s;
        $product->product_notice = $request->product_notice;
        $product->brand_c = $request->brand_c;
        $product->kg = $request->kg;
        $product->search_index = $request->search_index;
        $product->tags = implode('|',$request->tags);
        $product->description = $request->description;
        $product->video_provider = $request->video_provider;
        $product->video_link = $request->video_link;
        $product->unit_price = $request->unit_price;
        $product->purchase_price = $request->purchase_price;
        $product->tax = $request->tax;
        $product->tax_type = $request->tax_type;
        $product->discount = $request->discount;
        $product->discount_type = $request->discount_type;
        $product->shipping_type = $request->shipping;
        if($request->shipping == 'free'){
            $product->shipping_cost = 0;
        }
        elseif ($request->shipping == 'local_pickup') {
            $product->shipping_cost = $request->local_pickup_shipping_cost;
        }
        elseif ($request->shipping == 'flat_rate') {
            $product->shipping_cost = $request->flat_shipping_cost;
        }
        $product->meta_title = $request->meta_title;
        $product->meta_description = $request->meta_description;

        if($request->hasFile('meta_img')){
            $product->meta_img = $request->meta_img->store('uploads/products/meta');
            //ImageOptimizer::optimize(base_path('public/').$product->meta_img);
        }

        if($request->hasFile('pdf')){
            $product->pdf = $request->pdf->store('uploads/products/pdf');
        }

        $product->slug = strtolower(preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->name)).'-'.str_random(5));

        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
            $product->colors = json_encode($request->colors);
        }
        else {
            $colors = array();
            $product->colors = json_encode($colors);
        }

        $choice_options = array();

        if($request->has('choice')){
            foreach ($request->af_no as $key => $no) {
                $str = 'choice_options_'.$no;
                $item['name'] = 'choice_'.$no;
                $item['title'] = $request->choice[$key];
                $item['options'] = explode(',', $request[$str]);
                array_push($choice_options, $item);
            }
        }

        $product->attributes = json_encode($request->choice_attributes);

        $product->choice_options = json_encode($choice_options);

        //$product->variations = json_encode($variations);

        $additional_fields = array();
        if ($request->has('af_title')) {

            foreach ($request->af_title as $key => $af) {
                $additional['title'] = $request->af_title[$key];
                $additional['option'] = $request->af_options[$key];
                array_push($additional_fields, $additional);
            }
        }
        $product->additional_fields = json_encode($additional_fields);


        $variations = array();

        //combinations start
        $options = array();
        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
            $colors_active = 1;
            array_push($options, $request->colors);
        }

        if($request->has('choice_no')){
            foreach ($request->choice_no as $key => $no) {
                $name = 'choice_options_'.$no;
                $my_str = implode('|',$request[$name]);
                array_push($options, explode(',', $my_str));
            }
        }

        //Generates the combinations of customer choice options
        $combinations = combinations($options);
        if(count($combinations[0]) > 0){
            foreach ($combinations as $key => $combination){
                $str = '';
                foreach ($combination as $key => $item){
                    if($key > 0 ){
                        $str .= '-'.str_replace(' ', '', $item);
                    }
                    else{
                        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
                            $color_name = \App\Color::where('code', $item)->first()->name;
                            $str .= $color_name;
                        }
                        else{
                            $str .= str_replace(' ', '', $item);
                        }
                    }
                }
                $item = array();
                $item['price'] = $request['price_'.str_replace('.', '_', $str)];
                $item['sku'] = $request['sku_'.str_replace('.', '_', $str)];
                $item['qty'] = $request['qty_'.str_replace('.', '_', $str)];
                $variations[$str] = $item;
            }
        }
        //combinations end

        $product->variations = json_encode($variations);

        $data = openJSONFile('en');
        $data[$product->name] = $product->name;
        saveJSONFile('en', $data);

        if($product->save()){
            flash(__('Product has been inserted successfully'))->success();
            if(Auth::user()->user_type == 'admin'){
                return redirect()->route('products.admin');
            }
            else{
                return redirect()->route('seller.products');
            }
        }
        else{
            flash(__('Something went wrong'))->error();
            return back();
        }

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function admin_product_edit($id)
    {
        $product = Product::findOrFail(decrypt($id));
        //dd(json_decode($product->price_variations)->choices_0_S_price);
        $tags = json_decode($product->tags);
        $categories = Category::all();
        $states = State::all();
        return view('products.edit', compact('product', 'categories', 'tags', 'states'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function seller_product_edit($id)
    {
        $product = Product::findOrFail(decrypt($id));
        //dd(json_decode($product->price_variations)->choices_0_S_price);
        $tags = json_decode($product->tags);
        $categories = Category::all();
        $states = State::all();
        return view('products.edit', compact('product', 'categories', 'tags', 'states'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //dd($request->all());
        $product = Product::findOrFail($id);
        $product->name = $request->name;
        $product->sub_name = $request->sub_name;
        $product->category_id = $request->category_id;
        $product->subcategory_id = $request->subcategory_id;
        $product->subsubcategory_id = $request->subsubcategory_id;
        $product->brand_id = $request->brand_id;

        if ($request->product_type == 'internal') {
            $product->product_type =  $request->product_type;
            $product->available =  $request->shipping_type;
            $product->state_id =  $request->current_state;
            $shipment_details = array();
            foreach ($request->states as $key => $i) {
                $it['state_id'] = $i;
                $it['min_num_of_day'] = $request['min_num_of_day_'.$i];
                $it['max_num_of_day'] = $request['max_num_of_day_'.$i];
                array_push($shipment_details, $it);
            }
            $product->shipment_variation = json_encode($shipment_details);
            // dd($product->shipment_variation);
        }
        elseif ($request->product_type == 'external') {
            $product->product_type =  $request->product_type;
            $product->available =  'external';
            $shipment_details = array();
                $it['min_num_of_day'] = $request['min_num_of_day_'];
                $it['max_num_of_day'] = $request['max_num_of_day_'];
                array_push($shipment_details, $it);
            $product->shipment_variation = json_encode($shipment_details);
        }

        if($request->has('previous_photos')){
            $photos = $request->previous_photos;
        }
        else{
            $photos = array();
        }

        if($request->hasFile('photos')){
            foreach ($request->photos as $key => $photo) {
                $path = $photo->store('uploads/products/photos');
                array_push($photos, $path);
                //ImageOptimizer::optimize(base_path('public/').$path);
            }
        }
        $product->photos = json_encode($photos);

        $product->thumbnail_img = $request->previous_thumbnail_img;
        if($request->hasFile('thumbnail_img')){
            $product->thumbnail_img = $request->thumbnail_img->store('uploads/products/thumbnail');
            //ImageOptimizer::optimize(base_path('public/').$product->thumbnail_img);
        }

        $product->featured_img = $request->previous_featured_img;
        if($request->hasFile('featured_img')){
            $product->featured_img = $request->featured_img->store('uploads/products/featured');
            //ImageOptimizer::optimize(base_path('public/').$product->featured_img);
        }

        $product->flash_deal_img = $request->previous_flash_deal_img;
        if($request->hasFile('flash_deal_img')){
            $product->flash_deal_img = $request->flash_deal_img->store('uploads/products/flash_deal');
            //ImageOptimizer::optimize(base_path('public/').$product->flash_deal_img);
        }

        $product->unit = $request->unit;
        $product->link_s = $request->link_s;
        $product->product_notice = $request->product_notice;
        $product->brand_c = $request->brand_c;
        $product->kg = $request->kg;
        $product->published = 2;
         $product->search_index = $request->search_index;
        $product->tags = implode('|',$request->tags);
        $product->description = $request->description;
        $product->video_provider = $request->video_provider;
        $product->video_link = $request->video_link;
        $product->unit_price = $request->unit_price;
        $product->purchase_price = $request->purchase_price;
        $product->tax = $request->tax;
        $product->tax_type = $request->tax_type;
        $product->discount = $request->discount;
        $product->discount_type = $request->discount_type;
        $product->meta_title = $request->meta_title;
        $product->meta_description = $request->meta_description;

        $product->shipping_type = $request->shipping;
        if($request->shipping == 'free'){
            $product->shipping_cost = 0;
        }
        elseif ($request->shipping == 'local_pickup') {
            $product->shipping_cost = $request->local_pickup_shipping_cost;
        }
        elseif ($request->shipping == 'flat_rate') {
            $product->shipping_cost = $request->flat_shipping_cost;
        }

        $product->meta_img = $request->previous_meta_img;
        if($request->hasFile('meta_img')){
            $product->meta_img = $request->meta_img->store('uploads/products/meta');
            //ImageOptimizer::optimize(base_path('public/').$product->meta_img);
        }

        if($request->hasFile('pdf')){
            $product->pdf = $request->pdf->store('uploads/products/pdf');
        }

        //$product->slug = strtolower(preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->name)).'-'.substr($product->slug, -5));

        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
            $product->colors = json_encode($request->colors);
        }
        else {
            $colors = array();
            $product->colors = json_encode($colors);
        }

        $choice_options = array();

        if($request->has('choice_no')){
            foreach ($request->choice_no as $key => $no) {
                $str = 'choice_options_'.$no;
                $item['name'] = 'choice_'.$no;
                $item['title'] = $request->choice[$key];
                $item['options'] = explode(',', implode('|', $request[$str]));
                array_push($choice_options, $item);
            }
        }

        $product->attributes = json_encode($request->choice_attributes);

        $product->choice_options = json_encode($choice_options);

        foreach (Language::all() as $key => $language) {
            $data = openJSONFile($language->code);
            unset($data[$product->name]);
            $data[$request->name] = "";
            saveJSONFile($language->code, $data);
        }

        $variations = array();

        //combinations start
        $options = array();
        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
            $colors_active = 1;
            array_push($options, $request->colors);
        }

        if($request->has('choice_no')){
            foreach ($request->choice_no as $key => $no) {
                $name = 'choice_options_'.$no;
                $my_str = implode('|',$request[$name]);
                array_push($options, explode(',', $my_str));
            }
        }

        $combinations = combinations($options);
        if(count($combinations[0]) > 0){
            foreach ($combinations as $key => $combination){
                $str = '';
                foreach ($combination as $key => $item){
                    if($key > 0 ){
                        $str .= '-'.str_replace(' ', '', $item);
                    }
                    else{
                        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
                            $color_name = \App\Color::where('code', $item)->first()->name;
                            $str .= $color_name;
                        }
                        else{
                            $str .= str_replace(' ', '', $item);
                        }
                    }
                }
                $item = array();
                $item['price'] = $request['price_'.str_replace('.', '_', $str)];
                $item['sku'] = $request['sku_'.str_replace('.', '_', $str)];
                $item['qty'] = $request['qty_'.str_replace('.', '_', $str)];
                $variations[$str] = $item;
            }
        }
        //combinations end

        $product->variations = json_encode($variations);

        $additional_fields = array();
        if ($request->has('af_title')) {

            foreach ($request->af_title as $key => $af) {
                $additional['title'] = $request->af_title[$key];
                $additional['option'] = $request->af_options[$key];
                array_push($additional_fields, $additional);
            }
        }
        $product->additional_fields = json_encode($additional_fields);


        if($product->save()){
            flash(__('Product has been updated successfully'))->success();
            if(Auth::user()->user_type == 'admin'){
                return redirect()->route('products.admin');
            }
            else{
                return redirect()->route('seller.products');
            }
        }
        else{
            flash(__('Something went wrong'))->error();
            return back();
        }
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $product = Product::findOrFail($id);
        if(Product::destroy($id)){
            foreach (Language::all() as $key => $language) {
                $data = openJSONFile($language->code);
                unset($data[$product->name]);
                saveJSONFile($language->code, $data);
            }
            flash(__('Product has been deleted successfully'))->success();
            if(Auth::user()->user_type == 'admin'){
                return redirect()->route('products.admin');
            }
            else{
                return redirect()->route('seller.products');
            }
        }
        else{
            flash(__('Something went wrong'))->error();
            return back();
        }
    }

    /**
     * Duplicates the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function duplicate($id)
    {
        $product = Product::find($id);
        $product_new = $product->replicate();
        $product_new->slug = substr($product_new->slug, 0, -5).str_random(5);

        if($product_new->save()){
            flash(__('Product has been duplicated successfully'))->success();
            if(Auth::user()->user_type == 'admin'){
                return redirect()->route('products.admin');
            }
            else{
                return redirect()->route('seller.products');
            }
        }
        else{
            flash(__('Something went wrong'))->error();
            return back();
        }
    }

    public function get_products_by_subsubcategory(Request $request)
    {
        $products = Product::where('subsubcategory_id', $request->subsubcategory_id)->get();
        return $products;
    }

    public function get_products_by_brand(Request $request)
    {
        $products = Product::where('brand_id', $request->brand_id)->get();
        return view('partials.product_select', compact('products'));
    }

    public function updateTodaysDeal(Request $request)
    {
        $product = Product::findOrFail($request->id);
        $product->todays_deal = $request->status;
        if($product->save()){
            return 1;
        }
        return 0;
    }

    public function updatePublished(Request $request)
    {
        $product = Product::findOrFail($request->id);
        $product->published = $request->status;
        if($product->save()){
            return 1;
        }
        return 0;
    }

    public function updateFeatured(Request $request)
    {
        $product = Product::findOrFail($request->id);
        $product->featured = $request->status;
        if($product->save()){
            return 1;
        }
        return 0;
    }

    public function sku_combination(Request $request)
    {
        $options = array();
        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
            $colors_active = 1;
            array_push($options, $request->colors);
        }
        else {
            $colors_active = 0;
        }

        $unit_price = $request->unit_price;
        $product_name = $request->name;

        if($request->has('choice_no')){
            foreach ($request->choice_no as $key => $no) {
                $name = 'choice_options_'.$no;
                $my_str = implode('|', $request[$name]);
                array_push($options, explode(',', $my_str));
            }
        }

        $combinations = combinations($options);
        return view('partials.sku_combinations', compact('combinations', 'unit_price', 'colors_active', 'product_name'));
    }

    public function sku_combination_edit(Request $request)
    {
        $product = Product::findOrFail($request->id);

        $options = array();
        if($request->has('colors_active') && $request->has('colors') && count($request->colors) > 0){
            $colors_active = 1;
            array_push($options, $request->colors);
        }
        else {
            $colors_active = 0;
        }

        $product_name = $request->name;
        $unit_price = $request->unit_price;

        if($request->has('choice_no')){
            foreach ($request->choice_no as $key => $no) {
                $name = 'choice_options_'.$no;
                $my_str = implode('|', $request[$name]);
                array_push($options, explode(',', $my_str));
            }
        }

        $combinations = combinations($options);
        return view('partials.sku_combinations_edit', compact('combinations', 'unit_price', 'colors_active', 'product_name', 'product'));
    }

    public function shipment_duration_form(Request $request)
    {
        if($request->product_type == "external") {
            if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
                return view('partials.overseas_shipment_form');
            }
            else
                return view('frontend.partials.overseas_shipment_form');
        }
        elseif($request->product_type == "internal"){
            if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
                return view('frontend.partials.states_shipment_form');
            }
            else
                return view('frontend.partials.states_shipment_form');

        }
    }

    public function shipment_duration_form_edit(Request $request)
    {
        if($request->product_type == "external") {
            $product = Product::where('id', $request->id)->first();
            if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
                return view('partials.overseas_shipment_form_edit', compact('product'));
            }
            else
                 return view('frontend.partials.overseas_shipment_form_edit', compact('product'));
        }
        elseif($request->product_type == "internal"){
            $product = Product::where('id', $request->id)->first();
            if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
                return view('partials.states_shipment_form_edit', compact('product'));
            }
            else
                return view('frontend.partials.states_shipment_form_edit', compact('product'));
        }
    }

    public function get_shipment_form(Request $request){
        $state_ids = $request->state_ids;
        if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
            return view('partials.get_shipment_form', compact('state_ids'));
        }
        else
            return view('frontend.partials.get_shipment_form', compact('state_ids'));

    }

    public function get_shipment_form_edit(Request $request){
        $state_ids = $request->state_ids;
        $product = Product::findOrFail($request->product_id);
        if (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
            return view('partials.get_shipment_form_edit', compact('state_ids', 'product'));
        }
        else
            return view('frontend.partials.get_shipment_form_edit', compact('state_ids', 'product'));

    }

}
solaceng's avatar

Complete Route:

Auth::routes(['verify' => true]);
Route::get('/logout', '\App\Http\Controllers\Auth\LoginController@logout');
Route::post('/language', 'LanguageController@changeLanguage')->name('language.change');
Route::post('/currency', 'CurrencyController@changeCurrency')->name('currency.change');

Route::get('/social-login/redirect/{provider}', 'Auth\LoginController@redirectToProvider')->name('social.login');
Route::get('/social-login/{provider}/callback', 'Auth\LoginController@handleProviderCallback')->name('social.callback');
Route::get('/users/login', 'HomeController@login')->name('user.login');
Route::get('/users/registration', 'HomeController@registration')->name('user.registration');
Route::post('/users/login', 'HomeController@user_login')->name('user.login.submit');
Route::post('/users/login/cart', 'HomeController@cart_login')->name('cart.login.submit');

Route::post('/subcategories/get_subcategories_by_category', 'SubCategoryController@get_subcategories_by_category')->name('subcategories.get_subcategories_by_category');
Route::post('/subsubcategories/get_subsubcategories_by_subcategory', 'SubSubCategoryController@get_subsubcategories_by_subcategory')->name('subsubcategories.get_subsubcategories_by_subcategory');
Route::post('/subsubcategories/get_brands_by_subsubcategory', 'SubSubCategoryController@get_brands_by_subsubcategory')->name('subsubcategories.get_brands_by_subsubcategory');
Route::post('/subsubcategories/get_attributes_by_subsubcategory', 'SubSubCategoryController@get_attributes_by_subsubcategory')->name('subsubcategories.get_attributes_by_subsubcategory');

Route::get('/', 'HomeController@index')->name('home');
Route::get('/product/{slug}', 'HomeController@product')->name('product');
Route::get('/products', 'HomeController@listing')->name('products');
Route::get('/digital_products', 'HomeController@digital_listing')->name('digitalproducts');
Route::get('/search?category={category_slug}', 'HomeController@search')->name('products.category');
Route::get('/search?subcategory={subcategory_slug}', 'HomeController@search')->name('products.subcategory');
Route::get('/search?subsubcategory={subsubcategory_slug}', 'HomeController@search')->name('products.subsubcategory');
Route::get('/customer_product_search?subsubcategory={subsubcategory_slug}', 'CustomerProductController@search')->name('customer_products.subsubcategory');
Route::get('/customer_product_search?subcategory={subcategory_slug}', 'CustomerProductController@search')->name('customer_products.subcategory');
Route::get('/customer_product_search?category={category_slug}', 'CustomerProductController@search')->name('customer_products.category');
Route::get('/customer_product_search?city={city_id}', 'CustomerProductController@search')->name('customer_products.city');
Route::get('/customer_product_search?q={search}', 'CustomerProductController@search')->name('customer_products.search');
Route::get('/search?brand={brand_slug}', 'HomeController@search')->name('products.brand');
Route::get('/customer_product_search?brand={brand_slug}', 'CustomerProductController@search')->name('customer_products.brand');
Route::post('/product/variant_price', 'HomeController@variant_price')->name('products.variant_price');
Route::get('/shops/visit/{slug}', 'HomeController@shop')->name('shop.visit');
Route::get('/shops/visit/{slug}/{type}', 'HomeController@filter_shop')->name('shop.visit.type');
Route::get('/products/customer_products', 'HomeController@customer_products_listing')->name('customer.products');
Route::get('/customer_product/{slug}', 'HomeController@customer_product')->name('customer.product');

solaceng's avatar

Complete View:

This show both Category, Subcategory, subsubcategory and brand


@if(isset($subsubcategory_id))
    @php
        $meta_title = \App\SubSubCategory::find($subsubcategory_id)->meta_title;
        $meta_description = \App\SubSubCategory::find($subsubcategory_id)->meta_description;
    @endphp
    <link rel="canonical" href="{{ route('products.subsubcategory', \App\SubSubCategory::find($subsubcategory_id)->slug) }}" />
    
    @php
        $robots_subsubcat = \App\SubSubCategory::find($subsubcategory_id)->search_index;
    @endphp
    
    @if ($robots_subsubcat == '1' && $meta_title != null)
@section('robots'){{ __('index') }}@stop
@else
@section('robots'){{ __('noindex') }}@stop
@endif
   
@elseif (isset($subcategory_id))
    @php
        $meta_title = \App\SubCategory::find($subcategory_id)->meta_title;
        $meta_description = \App\SubCategory::find($subcategory_id)->meta_description;
    @endphp
    <link rel="canonical" href="{{ route('products.subcategory', \App\SubCategory::find($subcategory_id)->slug) }}" />
    
     @php
        $robots_subcat = \App\SubCategory::find($subcategory_id)->search_index;
    @endphp
    
    @if ($robots_subcat == '1' && $meta_title != null)
@section('robots'){{ __('index') }}@stop
@else
@section('robots'){{ __('noindex') }}@stop
@endif

@elseif (isset($category_id))
    @php
        $meta_title = \App\Category::find($category_id)->meta_title;
        $meta_description = \App\Category::find($category_id)->meta_description;
    @endphp
    <link rel="canonical" href="{{ route('products.category', \App\Category::find($category_id)->slug) }}" />
    
     @php
        $robots_cat = \App\Category::find($category_id)->search_index;
    @endphp
    
    @if ($robots_cat == '1' && $meta_title != null)
@section('robots'){{ __('index') }}@stop
@else
@section('robots'){{ __('noindex') }}@stop
@endif


@elseif (isset($brand_id))
    @php
        $meta_title = \App\Brand::find($brand_id)->meta_title;
        $meta_description = \App\Brand::find($brand_id)->meta_description;
    @endphp
    <link rel="canonical" href="{{ route('products.brand', \App\Brand::find($brand_id)->slug) }}" />
    
    @php
        $robots_cat = \App\Brand::find($brand_id)->c_search_index;
    @endphp
    
    @if ($robots_cat == '1' && $meta_title != null)
@section('robots'){{ __('index') }}@stop
@else
@section('robots'){{ __('noindex') }}@stop
@endif

    
@else
    @php
        $meta_title = env('APP_NAME');
        $meta_description = \App\SeoSetting::first()->description;
    @endphp
@endif





@section('meta_title'){{ $meta_title }}@stop
@section('meta_description'){{ $meta_description }}@stop

@section('meta')
    <!-- Schema.org markup for Google+ -->
    <meta itemprop="name" content="{{ $meta_title }}">
    <meta itemprop="description" content="{{ $meta_description }}">

    <!-- Twitter Card data -->
    <meta name="twitter:title" content="{{ $meta_title }}">
    <meta name="twitter:description" content="{{ $meta_description }}">

    <!-- Open Graph data -->
    <meta property="og:title" content="{{ $meta_title }}" />
    <meta property="og:description" content="{{ $meta_description }}" />
@endsection

@section('content')

    <div class="breadcrumb-area">
        <div class="container">
            <div class="row">
                <div class="col">
                    <ul class="breadcrumb">
                        <li><a href="{{ route('home') }}">{{__('Home')}}</a></li>
                        <li><a href="{{ route('products') }}">{{__('All Categories')}}</a></li>
                        @if(isset($category_id))
                            <li class="active"><a href="{{ route('products.category', \App\Category::find($category_id)->slug) }}">{{ \App\Category::find($category_id)->name }}</a></li>
                        @endif
                        @if(isset($subcategory_id))
                            <li ><a href="{{ route('products.category', \App\SubCategory::find($subcategory_id)->category->slug) }}">{{ \App\SubCategory::find($subcategory_id)->category->name }}</a></li>
                            <li class="active"><a href="{{ route('products.subcategory', \App\SubCategory::find($subcategory_id)->slug) }}">{{ \App\SubCategory::find($subcategory_id)->name }}</a></li>
                        @endif
                        @if(isset($subsubcategory_id))
                            <li ><a href="{{ route('products.category', \App\SubSubCategory::find($subsubcategory_id)->subcategory->category->slug) }}">{{ \App\SubSubCategory::find($subsubcategory_id)->subcategory->category->name }}</a></li>
                            <li ><a href="{{ route('products.subcategory', \App\SubsubCategory::find($subsubcategory_id)->subcategory->slug) }}">{{ \App\SubsubCategory::find($subsubcategory_id)->subcategory->name }}</a></li>
                            <li class="active"><a href="{{ route('products.subsubcategory', \App\SubSubCategory::find($subsubcategory_id)->slug) }}">{{ \App\SubSubCategory::find($subsubcategory_id)->name }}</a></li>
                        @endif
                    </ul>
                </div>
            </div>
        </div>
    </div>
   
    <section class="gry-bg py-4">
        <div class="container">
            <form id="search-form" action="{{ route('search') }}" method="GET">
                <div class="row">
                    <div class="col-xl-3 d-none d-xl-block">

                        <div class="bg-white sidebar-box mb-3">
                            <div class="box-title text-center">
                                {{__('Categories')}}
                            </div>
                            <div class="box-content">
                                <div class="category-accordion">
                                    @foreach (\App\Category::all() as $key => $category)
                                        <div class="single-category">
                                            <button class="btn w-100 category-name collapsed" type="button" data-toggle="collapse" data-target="#category-{{ $key }}" aria-expanded="true">
                                                {{ __($category->name) }}
                                            </button>

                                            <div id="category-{{ $key }}" class="collapse">
                                                @foreach ($category->subcategories as $key2 => $subcategory)
                                                    <div class="single-sub-category">
                                                        <button class="btn w-100 sub-category-name" type="button" data-toggle="collapse" data-target="#subCategory-{{ $key }}-{{ $key2 }}" aria-expanded="true">
                                                            {{ __($subcategory->name) }}
                                                        </button>
                                                        <div id="subCategory-{{ $key }}-{{ $key2 }}" class="collapse">
                                                            <ul class="sub-sub-category-list">
                                                                @foreach ($subcategory->subsubcategories as $key3 => $subsubcategory)
                                                                    <li><a href="{{ route('products.subsubcategory', $subsubcategory->slug) }}">{{ __($subsubcategory->name) }}</a></li>
                                                                @endforeach
                                                            </ul>
                                                        </div>
                                                    </div>
                                                @endforeach
                                            </div>
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                        <div class="bg-white sidebar-box mb-3">
                            <div class="box-title text-center">
                                {{__('Price range')}}
                            </div>
                            <div class="box-content">
                                <div class="range-slider-wrapper mt-3">
                                    <!-- Range slider container -->
                                    <div id="input-slider-range" data-range-value-min="{{ \App\Product::all()->min('unit_price') }}" data-range-value-max="{{ \App\Product::all()->max('unit_price') }}"></div>

                                    <!-- Range slider values -->
                                    <div class="row">
                                        <div class="col-6">
                                            <span class="range-slider-value value-low"
                                                @if (isset($min_price))
                                                    data-range-value-low="{{ $min_price }}"
                                                @elseif($products->min('unit_price') > 0)
                                                    data-range-value-low="{{ $products->min('unit_price') }}"
                                                @else
                                                    data-range-value-low="0"
                                                @endif
                                                id="input-slider-range-value-low">
                                        </div>

                                        <div class="col-6 text-right">
                                            <span class="range-slider-value value-high"
                                                @if (isset($max_price))
                                                    data-range-value-high="{{ $max_price }}"
                                                @elseif($products->max('unit_price') > 0)
                                                    data-range-value-high="{{ $products->max('unit_price') }}"
                                                @else
                                                    data-range-value-high="0"
                                                @endif
                                                id="input-slider-range-value-high">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="bg-white sidebar-box mb-3">
                            <div class="box-title text-center">
                                {{__('Filter by color')}}
                            </div>
                            <div class="box-content">
                                <!-- Filter by color -->
                                <ul class="list-inline checkbox-color checkbox-color-circle mb-0">
                                    @foreach ($all_colors as $key => $color)
                                        <li>
                                            <input type="radio" id="color-{{ $key }}" name="color" value="{{ $color }}" @if(isset($selected_color) && $selected_color == $color) checked @endif>
                                            <label style="background: {{ $color }};" for="color-{{ $key }}" onclick="galleryTop.slideTo(0)" data-toggle="tooltip" data-original-title="{{ \App\Color::where('code', $color)->first()->name }}"></label>
                                        </li>
                                    @endforeach
                                </ul>
                            </div>
                        </div>

                        @foreach ($attributes as $key => $attribute)
                            @if (\App\Attribute::find($attribute['id']) != null)
                                <div class="bg-white sidebar-box mb-3">
                                    <div class="box-title text-center">
                                        Filter by {{ \App\Attribute::find($attribute['id'])->name }}
                                    </div>
                                    <div class="box-content">
                                        <!-- Filter by others -->
                                        <div class="filter-checkbox">
                                            @if(array_key_exists('values', $attribute))
                                                @foreach ($attribute['values'] as $key => $value)
                                                    @php
                                                        $flag = false;
                                                        if(isset($selected_attributes)){
                                                            foreach ($selected_attributes as $key => $selected_attribute) {
                                                                if($selected_attribute['id'] == $attribute['id']){
                                                                    if(in_array($value, $selected_attribute['values'])){
                                                                        $flag = true;
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    @endphp
                                                    <div class="checkbox">
                                                        <input type="checkbox" id="attribute_{{ $attribute['id'] }}_value_{{ $value }}" name="attribute_{{ $attribute['id'] }}[]" value="{{ $value }}" @if ($flag) checked @endif>
                                                        <label for="attribute_{{ $attribute['id'] }}_value_{{ $value }}">{{ $value }}</label>
                                                    </div>
                                                @endforeach
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            @endif
                        @endforeach

                        <button type="submit" class="btn btn-styled btn-block btn-base-4">Apply filter</button>

                    </div>
                    <div class="col-xl-9">
                        <div class="bg-white px-3 pt-3">
                            @if(isset($query))
                                <h1 class="mb-0 heading-6 strong-500">
                                    Search result for <strong>{{$query}}</strong>
                                </h1>
                            @elseif(isset($category_id) || isset($subcategory_id) || isset($subsubcategory_id) || isset($brand_id))
                               <center> <h1 class="mb-0 heading-6 strong-500">
                                     <strong>
                                    @if(isset($category_id)) {{ \App\Category::find($category_id)->name }}@endif
                                    @if(isset($subcategory_id)) {{ \App\SubCategory::find($subcategory_id)->name }} @endif
                                    @if(isset($subsubcategory_id)) {{ \App\SubSubCategory::find($subsubcategory_id)->name }} @endif
                                    @if(isset($brand_id)) {{ \App\Brand::find($brand_id)->name }} @endif
                                    </strong>
                                </h1></center>
                            @else
                                <h1 class="mb-0 heading-6 strong-500">
                                    All Products
                                </h1>
                            @endif

                        </div>
                        <div class="brands-bar row no-gutters pb-3 bg-white p-3">
                            <div class="col-11">
                                <div class="brands-collapse-box" id="brands-collapse-box">
                                    <ul class="inline-links">
                                        @php
                                            $brands = array();
                                        @endphp
                                        @if(isset($subsubcategory_id))
                                            @php
                                                foreach (json_decode(\App\SubSubCategory::find($subsubcategory_id)->brands) as $brand) {
                                                    if(!in_array($brand, $brands)){
                                                        array_push($brands, $brand);
                                                    }
                                                }
                                            @endphp
                                        @elseif(isset($subcategory_id))
                                            @foreach (\App\SubCategory::find($subcategory_id)->subsubcategories as $key => $subsubcategory)
                                                @php
                                                    foreach (json_decode($subsubcategory->brands) as $brand) {
                                                        if(!in_array($brand, $brands)){
                                                            array_push($brands, $brand);
                                                        }
                                                    }
                                                @endphp
                                            @endforeach
                                        @elseif(isset($category_id))
                                            @foreach (\App\Category::find($category_id)->subcategories as $key => $subcategory)
                                                @foreach ($subcategory->subsubcategories as $key => $subsubcategory)
                                                    @php
                                                        foreach (json_decode($subsubcategory->brands) as $brand) {
                                                            if(!in_array($brand, $brands)){
                                                                array_push($brands, $brand);
                                                            }
                                                        }
                                                    @endphp
                                                @endforeach
                                            @endforeach
                                        @else
                                            @php
                                                foreach (\App\Brand::all() as $key => $brand){
                                                    if(!in_array($brand->id, $brands)){
                                                        array_push($brands, $brand->id);
                                                    }
                                                }
                                            @endphp
                                        @endif

                                        @foreach ($brands as $key => $id)
                                            @if (\App\Brand::find($id) != null)
                                                <li><a href="{{ route('products.brand', \App\Brand::find($id)->slug) }}"><img src="{{ asset(\App\Brand::find($id)->logo) }}" alt="" class="img-fluid"></a></li>
                                            @endif
                                        @endforeach
                                    </ul>
                                </div>
                            </div>
                            <div class="col-1">
                                <button type="button" name="button" onclick="morebrands(this)" class="more-brands-btn">
                                    <i class="fa fa-plus"></i>
                                    <span class="d-none d-md-inline-block">{{__('More')}}</span>
                                </button>
                            </div>
                        </div>

                            @isset($category_id)
                                <input type="hidden" name="category" value="{{ \App\Category::find($category_id)->slug }}">
                            @endisset
                            @isset($subcategory_id)
                                <input type="hidden" name="subcategory" value="{{ \App\SubCategory::find($subcategory_id)->slug }}">
                            @endisset
                            @isset($subsubcategory_id)
                                <input type="hidden" name="subsubcategory" value="{{ \App\SubSubCategory::find($subsubcategory_id)->slug }}">
                            @endisset

                            <div class="sort-by-bar row no-gutters bg-white mb-3 px-3">
                                <div class="col-lg-4 col-md-5">
                                    <div class="sort-by-box">
                                        <div class="form-group">
                                            <label>{{__('Search')}}</label>
                                            <div class="search-widget">
                                                <input class="form-control input-lg" type="text" name="q" placeholder="{{__('Search products')}}" @isset($query) value="{{ $query }}" @endisset>
                                                <button type="submit" class="btn-inner">
                                                    <i class="fa fa-search"></i>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-7 offset-lg-1">
                                    <div class="row no-gutters">
                                        <div class="col-4">
                                            <div class="sort-by-box px-1">
                                                <div class="form-group">
                                                    <label>{{__('Sort by')}}</label>
                                                    <select class="form-control sortSelect" data-minimum-results-for-search="Infinity" name="sort_by" onchange="filter()">
                                                        <option value="1" @isset($sort_by) @if ($sort_by == '1') selected @endif @endisset>{{__('Newest')}}</option>
                                                        <option value="2" @isset($sort_by) @if ($sort_by == '2') selected @endif @endisset>{{__('Oldest')}}</option>
                                                        <option value="3" @isset($sort_by) @if ($sort_by == '3') selected @endif @endisset>{{__('Price low to high')}}</option>
                                                        <option value="4" @isset($sort_by) @if ($sort_by == '4') selected @endif @endisset>{{__('Price high to low')}}</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-4">
                                            <div class="sort-by-box px-1">
                                                <div class="form-group">
                                                    <label>{{__('Brands')}}</label>
                                                    <select class="form-control sortSelect" data-placeholder="{{__('All Brands')}}" name="brand" onchange="filter()">
                                                        <option value="">{{__('All Brands')}}</option>
                                                        @foreach ($brands as $key => $id)
                                                            @if (\App\Brand::find($id) != null)
                                                                <option value="{{ \App\Brand::find($id)->slug }}" @isset($brand_id) @if ($brand_id == $id) selected @endif @endisset>{{ \App\Brand::find($id)->name }}</option>
                                                            @endif
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-4">
                                            <div class="sort-by-box px-1">
                                                <div class="form-group">
                                                    <label>{{__('Sellers')}}</label>
                                                    <select class="form-control sortSelect" data-placeholder="{{__('All Sellers')}}" name="seller_id" onchange="filter()">
                                                        <option value="">{{__('All Sellers')}}</option>
                                                        @foreach (\App\Seller::all() as $key => $seller)
                                                            <option value="{{ $seller->id }}" @isset($seller_id) @if ($seller_id == $seller->id) selected @endif @endisset>{{ $seller->user->shop->name }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                 <!-- Switch-->
                        
@if(isset($subsubcategory_id))
   

    
    <a href="{{ route('customer_products.subsubcategory',  \App\SubSubCategory::find($subsubcategory_id)->slug) }}" class="btn-base-1 btn-outline btn-sm price-box float-right">View Ads  Under {{ \App\SubSubCategory::find($subsubcategory_id)->name }}</a>
    
   
@elseif (isset($subcategory_id))
    
    <a href="{{ route('customer_products.subcategory',  \App\SubCategory::find($subcategory_id)->slug) }}" class="btn-base-1 btn-outline btn-sm price-box float-right">View Ads  Under {{ \App\SubCategory::find($subcategory_id)->name }}</a>
   

@elseif (isset($category_id))
   
    
    <a href="{{ route('customer_products.category',  \App\Category::find($category_id)->slug) }}" class="btn-base-1 btn-outline btn-sm price-box float-right">View Ads  Under {{ \App\Category::find($category_id)->name }}</a>
   
    
   
@elseif (isset($brand_id))

 
  <a href="{{ route('customer_products.brand', \App\Brand::find($brand_id)->slug) }}" class="btn-base-1 btn-outline btn-sm price-box float-right">View Ads  Under {{ \App\Brand::find($brand_id)->name }}</a>
   
    
@else
  
  <a href="/" class="btn-base-1 btn-outline btn-sm price-box float-right">Go to Homepage</a>
   
  
@endif

                    
                        <!---switch end-->

                            </div>
                            <input type="hidden" name="min_price" value="">
                            <input type="hidden" name="max_price" value="">

                        <!-- <hr class=""> -->
                       
                        
                        <div class="products-box-bar p-sm-3 p-2 bg-white">
                            <div class="row sm-no-gutters gutters-5">
                                @foreach ($products as $key => $product)
                                    <div class="col-xxl-3 col-xl-4 col-lg-3 col-md-4 col-6">
                                        <div class="product-box-2 bg-white alt-box my-sm-2">
                                            <div class="position-relative overflow-hidden">
                                                <a href="{{ route('product', $product->slug) }}" class="d-block product-image h-100" style="background-image:url('{{ asset($product->thumbnail_img) }}');" tabindex="0">
                                                </a>
                                               
                                                <div class="product-btns clearfix">
                                                    <button class="btn add-wishlist" title="Add to Wishlist" onclick="addToWishList({{ $product->id }})" tabindex="0">
                                                        <i class="la la-heart-o"></i>
                                                    </button>
                                                    <button class="btn add-compare" title="Add to Compare" onclick="addToCompare({{ $product->id }})" tabindex="0">
                                                        <i class="la la-refresh"></i>
                                                    </button>
                                                    <button class="btn quick-view" title="Quick view" onclick="showAddToCartModal({{ $product->id }})" tabindex="0">
                                                        <i class="la la-eye"></i>
                                                    </button>
                                                </div>
                                            </div>
                                            <div class="p-sm-3 p-2 border-top">
                                                <h2 class="product-title p-0 text-truncate">
                                                    <a href="{{ route('product', $product->slug) }}" tabindex="0">{{ __($product->name) }}</a>
                                                    @if ($product->product_type == 'internal')
                                                       <!-- <img src="{{ asset(\App\BusinessSetting::where('type', 'internal_icon')->first()->value) }}" alt="" height="16px">-->
                                                       <div class="small"><font color="green">Already In Nigeria</font></div>
                                                    @elseif ($product->product_type == 'external')
                                                      <!--  <img src="{{ asset(\App\BusinessSetting::where('type', 'external_icon')->first()->value) }}" alt="" height="16px">-->
                                                      <div class="small"><font color="green">Shipped from Abroad</font></div>
                                                    @endif
                                                </h2>
                                                
                                                       <div class="star-rating mb-1">
                                                 
                                                    @php
                                                        $total = 0;
                                                        $total += $product->reviews->count();
                                                    @endphp
                                                     @if ($total < '1')
                                                     <div class="small"><font color="green">AfoWoW</font></div><div> </div>
                                                    @else  
                                                    {{ renderStarRating($product->rating) }}
                                                     @endif
                                                    @if ($total > '999')
                                                        (1000+ {{__('reviews')}})
                                                    @elseif ($total < '1')
                                                        
                                                    @else
                                                        ({{ $total }})
                                                    @endif
                                                    
                                                </div>
                                                <div class="clearfix">
                                                    <div class="price-box float-left">
                                                        <span class="product-price strong-600">{{ home_discounted_base_price($product->id) }}</span>
                                                     
                                                 </div>
                                                
                                                 </div>
                                                 @if(home_base_price($product->id) != home_discounted_base_price($product->id))
                                                   <span class="btn-base-1 btn-outline btn-sm price-box float-right">-{{discounted_percent($product->id)}}%</span>
                                           @endif
                                                   <span class="price-box"><del>{{ home_price($product->id) }}</del></span>
                                                 
                                            </div>
                                        </div>
                                        <!-- <div class="product-card-1 mb-2">
                                            <figure class="product-image-container">
                                                <a href="{{ route('product', $product->slug) }}" class="product-image d-block" style="background-image:url('{{ asset($product->thumbnail_img) }}');">
                                                </a>
                                                <button class="btn-quickview" onclick="showAddToCartModal({{ $product->id }})"><i class="la la-eye"></i></button>
                                                @if (strtotime($product->created_at) > strtotime('-10 day'))
                                                    <span class="product-label label-hot">{{__('New')}}</span>
                                                @endif
                                            </figure>
                                            <div class="product-details text-center">
                                                <h2 class="product-title text-truncate mb-0">
                                                    <a href="{{ route('product', $product->slug) }}">{{ __($product->name) }}</a>
                                                </h2>
                                                <div class="star-rating star-rating-sm mt-1 mb-2">
                                                    {{ renderStarRating($product->rating) }}
                                                </div>
                                                <div class="price-box">
                                                    @if(home_base_price($product->id) != home_discounted_base_price($product->id))
                                                        <span class="old-product-price strong-300">{{ home_base_price($product->id) }}</span>
                                                    @endif
                                                    <span class="product-price strong-300"><strong>{{ home_discounted_base_price($product->id) }}</strong></span>
                                                </div>

                                                <div class="product-card-1-action">
                                                    <button class="paction add-wishlist" title="Add to Wishlist" onclick="addToWishList({{ $product->id }})">
                                                        <i class="la la-heart-o"></i>
                                                    </button>

                                                    <button type="button" class="paction add-cart btn btn-base-1 btn-circle btn-icon-left" onclick="showAddToCartModal({{ $product->id }})">
                                                        <i class="fa la la-shopping-cart mr-0 mr-sm-2"></i><span class="d-none d-sm-inline-block">{{__('Add to cart')}}</span>
                                                    </button>

                                                    <button class="paction add-compare" title="Add to Compare" onclick="addToCompare({{ $product->id }})">
                                                        <i class="la la-refresh"></i>
                                                    </button>
                                                </div>
                                            </div>
                                        </div> -->
                                    </div>
                                @endforeach
                            </div>
                        </div>
                        <div class="products-pagination bg-white p-3">
                            <nav aria-label="Center aligned pagination">
                                <ul class="pagination justify-content-center">
                                    {{ $products->links() }}
                                </ul>
                            </nav>
                        
                        </div>
                         <!-- featured category -->
             <div class="d-lg-block">
                        <div class="row no-gutters">
                            @foreach (\App\Category::where('featured', 1)->get()->take(6) as $key => $category)
                                <div class="col-4">
                                    <div class="custom-cat-box text-center">
                                        <a href="{{ route('products.category', $category->slug) }}" class="d-block">
                                            <div class="img">
                                                <img src="{{ asset($category->banner) }}" class="img-fluid circle">
                                            </div>
                                            <div class="name text-truncate-2">{{ __($category->name) }}</div>
                                        </a>
                                    </div>
                                </div>
                            @endforeach
                          </div>
                        <!--Cat lond description-->
@if(isset($category_id))
    @php
        $long_dec = \App\Category::find($category_id)->long_dec;
    @endphp
    
     <class class="col-2">
                                    
                                     <?php echo $long_dec; ?>
                                </div>
                                @endif
                    </div>
              
                <!-- featured category end-->
                    </div>

                </div>
            </form>
        
        </div>
        
          
    </section>

@endsection

@section('script')
    <script type="text/javascript">
        function filter(){
            $('#search-form').submit();
        }
        function rangefilter(arg){
            $('input[name=min_price]').val(arg[0]);
            $('input[name=max_price]').val(arg[1]);
            //filter();
        }
    </script>
@endsection```
solaceng's avatar

The site is already running. I discovered that the developer views the category, subcategory and subsubcategory under one view that's why am find it difficult. I need a help to separate them on different views so that the URL could be possible.

solaceng's avatar

This is the most important because is where he defined the route

Route::get('/product/{slug}', 'HomeController@product')->name('product');
Route::get('/products', 'HomeController@listing')->name('products');
Route::get('/digital_products', 'HomeController@digital_listing')->name('digitalproducts');
Route::get('/search?category={category_slug}', 'HomeController@search')->name('products.category');
Route::get('/search?subcategory={subcategory_slug}', 'HomeController@search')->name('products.subcategory');
Route::get('/search?subsubcategory={subsubcategory_slug}', 'HomeController@search')->name('products.subsubcategory');
Route::get('/customer_product_search?subsubcategory={subsubcategory_slug}', 'CustomerProductController@search')->name('customer_products.subsubcategory');```
Tray2's avatar

And that is what I would convert to

Route::get('/search/products', 'SearchProductsController@index);

Or

Route::get('/products/search', 'ProductsSearchController@index'

Then I would do something like

public function index(Request $request)
{
    if(isset($request->query('category_slug') {
        $products = Product::where('category_slug', $request->query('category_slug');
        } else if (isset($request->query('subcategory_slug') {
        $products = Product::where('subcategory_slug', $request->query('subcategory_slug');
        }

    return view('products.index')->with(['products' => $products]);
}

If you have a categories table you need to adapt the eloquent queries.

solaceng's avatar

There is an error in the code. check


public function index(Request $request)
{
    if(isset($request->query('category_slug') {
        $products = Product::where('category_slug', $request->query('category_slug');
        }
        
        else if (isset($request->query('subcategory_slug') {
        $products = Product::where('subcategory_slug', $request->query('subcategory_slug');
        }

Please or to participate in this conversation.