lundi 5 février 2018

laravel getting error in one to manay relationship

i am trying to get record(one to many) from database. but i only provide me product table data not both

table structure

enter image description here

enter image description here

my model

namespace App;

use Illuminate\Database\Eloquent\Model;

class brand extends Model
{
protected $table="brand";
 protected $primaryKey = 'brand_id';

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

}

my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\brand;

class BrandController extends Controller
{
/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{

   $val=brand::with('product')->find(5)->product;



 foreach($val as $va){

  echo print_r($val);

 }
}

it provide me the record from product table not from both table



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire