Skip to main content

Missing required parameters for [Route: show.product] [URI: products/{id}/{slug}]

I bought this script from an codecanyon and I have a little experience with php. I'm using a different template. So, I'm customizing the front end and connecting with backend. Been on this error since the first week of December, last year. Made some progress so I'm kinda hooked

PS: I want to use mainly simple product The script has the products, simple products, and digital products. However, when you create a simple products, it gets saved to the simple products directory in mysql. And not the products. I really need help with getting pass this error. I am working on a fashion store. I want to add a section for featured products on the homepage, I'm stuck for weeks now.

Please does anyone know what I could do to solve this. Am I doing it right?

Thanks in advance.

ROUTE

Web.php

Route::get('/','Web\HomeController@newHomepage')->name('mainindex')->middleware('visiting_track');

Route::get('products/{id}/{slug}','SimpleProductsController@show')->name('show.product');

MODEL

SimpleProduct.PHP

<?php

namespace App;

use CyrildeWit\EloquentViewable\Contracts\Viewable;
use CyrildeWit\EloquentViewable\InteractsWithViews;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;

class SimpleProduct extends Model implements Viewable
{

    use SoftDeletes;
    use HasTranslations;
    use InteractsWithViews;

    public $translatable = ['product_name', 'product_detail','key_features','sale_tag'];

    protected $fillable = [
        'product_name',
        'slug',
        'product_detail',
        'category_id',
        'product_tags',
        'price',
        'offer_price',
        'tax',
        'tax_rate',
        'thumbnail',
        'hover_thumbnail',
        'product_file',
        'status',
        'store_id',
        'brand_id',
        'type',
        'key_features',
        'subcategory_id',
        'child_id',
        'tax_name',
        'free_shipping',
        'featured',
        'cancel_avbl',
        'cod_avbl',
        'return_avbl',
        'tax_name',
        'model_no',
        'sku',
        'hsin',
        'policy_id',
        'actual_offer_price',
        'actual_selling_price',
        'commission_rate',
        'stock',
        'min_order_qty',
        'max_order_qty',
        'external_product_link',
        '360_image',
        'sale_tag_color',
        'sale_tag_text_color',
        'sale_tag'
    ];

    public function productGallery()
    {

        return $this->hasMany('App\ProductGallery', 'product_id')->withTrashed();

    }

    public function category()
    {
        return $this->belongsTo('App\Category', 'category_id', 'id');
    }

    public function subcategory()
    {
        return $this->belongsTo('App\Subcategory', 'subcategory_id', 'id');
    }

    public function childcat()
    {
        return $this->belongsTo('App\Grandcategory', 'child_id', 'id');
    }

    public function store()
    {
        return $this->belongsTo('App\Store', 'store_id', 'id');
    }

    public function brand()
    {
        return $this->belongsTo('App\Brand', 'brand_id', 'id');
    }

    public function reviews()
    {
        return $this->hasMany('App\UserReview', 'simple_pro_id');
    }

    public function comments()
    {
        return $this->hasMany('App\Comment', 'simple_pro_id');
    }

    public function returnPolicy()
    {
        return $this->belongsTo('App\admin_return_product', 'policy_id','id');
    }

    public function faq()
    {
        return $this->hasMany('App\FaqProduct', 'simple_pro_id');
    }

    public function specs()
    {
        return $this->hasMany('App\ProductSpecifications', 'simple_pro_id');
    }

    public function frames(){
        return $this->hasMany('App\Product360Frame','product_id');
    }

    public function cashback_settings(){
        return $this->hasOne('App\Cashback','simple_product_id','id');
    }

    public function hotdeal(){
        return $this->hasOne('App\Hotdeal','simple_pro_id','id');
    }

    public function special_offer(){
        return $this->hasOne('App\SpecialOffer','simple_pro_id','id');
    }

    public function flashdeal(){
        return $this->hasMany('App\FlashSaleItem','simple_product_id');
    }

}

BLADE FILE

homepage.blade.php

@extends("front.layout.newhome")

<?php
$sellerSystem = App\Genral::select('vendor_enable')->first();

$featuredproducts = App\SimpleProduct::where('status','=','1')->where('featured', '=', '1')->orderBy('id', 'DESC')->take(5)->get();

?>

@section('meta_tags')
<link rel="canonical" href=""/>
<meta name="keywords" content="">
<meta property="og:title" content="" />
<meta property="og:description" content="" />
<meta property="og:type" content="WebPage"/>
<meta property="og:url" content="" />
<meta property="og:image" content="" />
<meta name="twitter:card" content="summary" />

@endsection
@section("content")
<div class="main-container">
    <section class="image-slider slider-all-controls parallax controls-inside pt0 pb0">
        <ul class="slides">                       
            <li class="overlay image-bg pt240 pb240 pt-xs-120 pb-xs-120">
                <div class="background-image-holder">
                    <img alt="image" class="background-image" src="img/slide2.jpg">
                </div>
                <div class="container">
                    <div class="row text-center">
                        <div class="col-md-12">
                            <h2 class="mb40 uppercase">Embrace the New</h2>
                            <a class="btn btn-lg" href="#">Explore Collection</a>
                        </div>
                    </div>
                    <!--end of row-->
                </div>
                <!--end of container-->
            </li>
        </ul>
    </section>
    
    <section class="pt40 pb0">
        <div class="container">
            <div class="row">
                <div class="col-sm-6">
                    <div class="image-tile inner-title title-center text-center">
                        <a href="#">
                            <img alt="Pic" src="img/fashion2.jpg"/>
                            <div class="title">
                                <h4 class="uppercase mb0">Fall Lookbook</h4>
                            </div>
                        </a>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="image-tile inner-title title-center text-center">
                        <img alt="Pic" src="img/fashion3.jpg"/>
                        <div class="title">
                            <div class="modal-container">
                                <div class="play-button btn-modal inline"></div>
                                <div class="foundry_modal no-bg">
                                    <iframe data-provider="vimeo" data-video-id="63344039" data-autoplay="1"
                                            allowfullscreen="allowfullscreen"></iframe>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <section class="pt40 pb0">
        <div class="container">
            <div class="row">
                <div class="col-sm-12 text-center">
                    <h6 class="uppercase mb0">Featured Products</h6>
                </div>
            </div>
        </div>
    </section>

    <section class="pt40 pb0">
        <div class="container">
            <div class="row">  

                @foreach ($featuredproducts as $item)
                
                    <div class="col-md-3 col-sm-4">
                        <div class="image-tile outer-title text-center">
                            <a href="" title="">
                                <img alt="Pic" class="product-thumb" src=""/>
                            </a>
                            <div class="title">
                                <a title="View product" href=""><h5
                                            class="mb0"></h5></a>
                                 </span> --}}
                            </div>
                        </div>
                    </div>
                    <!--end three col-->
                    @if($loop->iteration == 4)
                        @break
                    @endif
                @endforeach 
            <!--end three col-->
            </div>
            <!--end of row-->
        </div>
        <!--end of container-->
    </section>  

Controller

HomeController.php

<?php

namespace App\Http\Controllers\Web;

use App\AddSubVariant;
use App\Blog;
use App\Cart;
use App\Category;
use App\CategorySlider;
use App\SimpleProduct;
use App\FrontCat;
use App\Genral;
use App\Grandcategory;
use App\Helpers\CategoryUrl;
use App\Helpers\ChidCategoryUrl;
use App\Helpers\ProductUrl;
use App\Helpers\SubcategoryUrl;
use App\Http\Controllers\Api\CartController;
use App\Http\Controllers\Api\CurrencyController;
use App\Http\Controllers\Api\MainController;
use App\Http\Controllers\Controller;
use App\Menu;
use App\OfferPopup;
use App\Product;
use App\Slider;
use App\Subcategory;
use App\Testimonial;
use App\Widgetsetting;
use App\Wishlist;
use Avatar;
use GuestCartShipping;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Mtownsend\ReadTime\ReadTime;
use ProductRating;
use ShippingPrice;

class HomeController extends Controller
{
    public function __construct()
    {
        try{
            
            $this->sellerSystem = Genral::select('vendor_enable')->first();
           
        }catch(\Exception $e){
            
        }
    }

    public function newHomepage()
    {
        require base_path() . '/app/Http/Controllers/price.php';

        $offersettings = OfferPopup::first();

        return view('front.homepage', compact('conversion_rate','offersettings'));
    }

public function simple_products(){

        $conversion_rate = new CurrencyController;

        $sellerSystem = $this->sellerSystem;

        $conversion_rate = $conversion_rate->fetchRates(session()->get('currency')['id'])->getData()->exchange_rate;

        $simple_products = SimpleProduct::with('category')->whereHas('category',function($q){

            $q->where('status','=','1');

        })->with('subcategory')->wherehas('subcategory',function($q){

            $q->where('status','1');

        })->with('store')->whereHas('store',function($query){
    
            return $query->where('status','=','1');
    
        })->whereHas('store.user',function($query) use ($sellerSystem) {
            
            if($sellerSystem->vendor_enable == 1){
                $query->where('status','=','1')->where('is_verified','1');
            }else{
                $query->where('status','=','1')->where('role_id','=','a')->where('is_verified','1');
            }

        })->where('status','=','1')->where('featured', '=', '1')->orderBy('id', 'DESC')->take(20)->get();

       

        return $simple_products->map(function($content) use($conversion_rate) {

            $content['productid'] = $content->id;
            $content['productname'] = $content->getTranslations('product_name');

            $content['mainprice'] = price_format($content->price * $conversion_rate);

            $content['offerprice'] = price_format($content->offer_price * $conversion_rate);
            $content['thumbnail'] = url('images/simple_products/' . $content->thumbnail);
            $content['hover_thumbnail'] = url('images/simple_products/' . $content->hover_thumbnail);
            $content['is_in_wishlist'] =  inwishlist($content->id) == false ? 0 : 1;
            $content['stock'] = $content->stock;
            $content['featured'] = $content->featured;
            $content['type'] = $content->type;
            $content['rating'] = 0;
            $content['pricein'] = session()->get('currency')['id'];
            $content['symbol'] = session()->get('currency')['value'];
            $content['position'] = session()->get('currency')['position'];
            $content['cartURL'] = route('add.cart.vue.simple',['pro_id' => $content->id, 'price' => $content->price, 'offerprice' => $content->offer_price, 'qty' => $content->min_order_qty]);

            $content['producturl'] = route('show.product',['id' => $content->id, 'slug' => $content->slug]);
            $content['sale_tag'] = $content->getTranslations('sale_tag');
            $content['sale_tag_color'] = $content->sale_tag_color;
            $content['sale_tag_text_color'] = $content->sale_tag_text_color;

            return $content;

        });

    }

public function featuredProducts()
    {   
        $sellerSystem = $this->sellerSystem;

        $featuredproducts = Product::with('category')->whereHas('category',function($q){

            $q->where('status','=','1');

        })->with('subcategory')->wherehas('subcategory',function($q){

            $q->where('status','1');

        })->with('vender')->whereHas('vender',function($query) use ($sellerSystem) {
 
            if($sellerSystem->vendor_enable == 1){
                $query->where('status','=','1')->where('is_verified','1');
            }else{
                $query->where('status','=','1')->where('role_id','=','a')->where('is_verified','1');
            }
    
        })->with('store')->whereHas('store',function($query){
    
            return $query->where('status','=','1');
    
        })->with('subvariants')->whereHas('subvariants',function($query){
    
            $query->where('def','=','1');
    
        })->with('subvariants.variantimages')->whereHas('subvariants.variantimages')->where('status','=','1')->where('featured', '=', '1')->orderBy('id', 'DESC')->take(20)->get();
        


        $get_product_data = new MainController;

        $conversion_rate = new CurrencyController;

        $conversion_rate = $conversion_rate->fetchRates(session()->get('currency')['id'])->getData()->exchange_rate;

        $content = array();

        $featuredproducts = $featuredproducts->map(function ($q) use ($get_product_data, $content, $conversion_rate) {

            $orivar = $q->subvariants[0];

            if (isset($orivar)) {

                $variant = $get_product_data->getVariant($orivar);
                $variant = $variant->getData();
                $mainprice = $get_product_data->getprice($q, $orivar);
                $price = $mainprice->getData();
                $rating = $get_product_data->getproductrating($q);

                $content['productid'] = $q->id;
                $content['variantid'] = $orivar->id;
                $content['productname'] = $q->getTranslations('name');
                $content['product_type'] = 'variant';
                $content['selling_start_at'] = $q->selling_start_at;

                $content['mainprice'] = price_format($price->mainprice * $conversion_rate);

                $content['offerprice'] = price_format($price->offerprice * $conversion_rate);

                $content['rating'] = (double) $rating;
                $content['thumbnail'] = url('variantimages/thumbnails/' . $orivar->variantimages->main_image);
                $content['hover_thumbnail'] = url('variantimages/hoverthumbnail/' . $orivar->variantimages->image2);
                $content['is_in_wishlist'] = $this->isItemInWishlist($orivar);
                $content['stock'] = $orivar->stock;
                $content['featured'] = $q->featured;
                $content['rating'] = ProductRating::getReview($q);
                $content['pricein'] = session()->get('currency')['id'];
                $content['symbol'] = session()->get('currency')['value'];
                $content['position'] = session()->get('currency')['position'];
                $content['cartURL'] = route('add.cart.vue', ['id' => $q->id, 'variantid' => $orivar->id, 'varprice' => $price->mainprice, 'varofferprice' => $price->offerprice, 'qty' => $orivar->min_order_qty]);

                $content['producturl'] = $q->getURL($orivar);
                $content['sale_tag'] = $q->getTranslations('sale_tag');
                $content['sale_tag_color'] = $q->sale_tag_color;
                $content['sale_tag_text_color'] = $q->sale_tag_text_color;
                return $content;

            }

        });

        $featuredproducts = $featuredproducts->merge($this->simple_products());

        return $featuredproducts->filter()->shuffle();
    }

public function categoryproducts($top_categories, $category)
    {

        $sellerSystem = $this->sellerSystem;
       
        $topcatproducts = Product::with('category')->whereHas('category',function($q) use($category) {

            $q->where('status','=','1')->where('id',$category->id);

        })->with('subcategory')->wherehas('subcategory',function($q){

            $q->where('status','1');

        })->with('vender')->whereHas('vender',function($query) use ($sellerSystem) {
 
            if($sellerSystem->vendor_enable == 1){
                $query->where('status','=','1')->where('is_verified','1');
            }else{
                $query->where('status','=','1')->where('role_id','=','a')->where('is_verified','1');
            }
    
        })->with('store')->whereHas('store',function($query){
    
            return $query->where('status','=','1');
    
        })->with('subvariants')->whereHas('subvariants',function($query){
    
            $query->where('def','=','1');
    
        })
        ->with('subvariants.variantimages')
        ->whereHas('subvariants.variantimages')
        ->where('status','=','1')->orderBy('id', 'DESC')
        ->take($top_categories->pro_limit)
        ->get();
        

        $get_product_data = new MainController;

        $conversion_rate = new CurrencyController;

        $conversion_rate = $conversion_rate->fetchRates(session()->get('currency')['id'])->getData()->exchange_rate;

        $content = array();

        $topcatproducts = $topcatproducts->map(function ($q) use ($get_product_data, $content, $conversion_rate) {

            $orivar = $q->subvariants[0];

            if (isset($orivar)) {

                $variant = $get_product_data->getVariant($orivar);
                $variant = $variant->getData();
                $mainprice = $get_product_data->getprice($q, $orivar);
                $price = $mainprice->getData();

                $content['productid'] = $q->id;
                $content['variantid'] = $orivar->id;
                $content['productname'] = $q->getTranslations('name');
                $content['selling_start_at'] = $q->selling_start_at;
                $content['product_type'] = 'variant';
                $content['mainprice'] = price_format($price->mainprice * $conversion_rate);

                $content['offerprice'] = price_format($price->offerprice * $conversion_rate);

                $content['pricein'] = session()->get('currency')['id'];
                $content['symbol'] = session()->get('currency')['value'];
                $content['position'] = session()->get('currency')['position'];

                $content['thumbnail'] = url('variantimages/thumbnails/' . $orivar->variantimages->main_image);
                $content['hover_thumbnail'] = url('variantimages/hoverthumbnail/' . $orivar->variantimages->image2);
                $content['is_in_wishlist'] = $this->isItemInWishlist($orivar);
                $content['stock'] = $orivar->stock;
                $content['featured'] = $q->featured;
                $content['rating'] = ProductRating::getReview($q);
                $content['cartURL'] = route('add.cart.vue', ['id' => $q->id, 'variantid' => $orivar->id, 'varprice' => $price->mainprice, 'varofferprice' => $price->offerprice, 'qty' => $orivar->min_order_qty]);

                $content['producturl'] = $q->getURL($orivar);

                $content['sale_tag'] = $q->getTranslations('sale_tag');
                $content['sale_tag_color'] = $q->sale_tag_color;
                $content['sale_tag_text_color'] = $q->sale_tag_text_color;
                return $content;

            }

        });

        $topcatproducts = $topcatproducts->merge($this->tabbed_simple_products($category->id));

        $topcatproducts = $topcatproducts->filter()->shuffle();

        return $topcatproducts;

    }



source https://stackoverflow.com/questions/70625784/missing-required-parameters-for-route-show-product-uri-products-id-slug

Comments

Popular posts from this blog

Prop `className` did not match in next js app

I have written a sample code ( Github Link here ). this is a simple next js app, but giving me error when I refresh the page. This seems to be the common problem and I tried the fix provided in the internet but does not seem to fix my issue. The error is Warning: Prop className did not match. Server: "MuiBox-root MuiBox-root-1" Client: "MuiBox-root MuiBox-root-2". Did changes for _document.js, modified _app.js as mentioned in official website and solutions in stackoverflow. but nothing seems to work. Could someone take a look and help me whats wrong with the code? Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console