i am trying to get record(one to many) from database. but i only provide me product table data not both
table structure
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