dimanche 24 février 2019

RelationNotFoundException Call to undefined relationship Laravel

enter image description here

Why i am getting error for Laravel relationship. I am trying to print_r the values with this relationship. is there any way to get rid of this error?

Controller: this is cart page functions

public function cart_page()

  {
     $session_id = Session::get('session_id');

     $viewData = cartmodel::with('product_tbls')->where('session_id', $session_id) -> get();

    echo "<pre>";  print_r($viewData); die;

     // return view('pages.cart', compact('viewData'));

  }

Products_model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class product_models extends Model
{
   protected $table ="product_tbls";

   public function shop_product_all()

   {

      return $this -> hasMany('App\cartmodel');

   }


}

Cart model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class cartmodel extends Model
{
  protected $table ="shoppingcart";

  public function shopcart_product()


  {

    return $this -> belongsTo('App\product_models');

  }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire