I'm using Laravel 5.1 Just want to ask how to display ORM master detail when child return no data the the master data is not showing
This is My Master Model
<?php
namespace SpekWeb;
use Illuminate\Database\Eloquent\Model;
class ProdukGroup extends Model
{
public $table = 'product_group';
public $primaryKey = 'prd_group';
public function telcoProduct() {
return $this->hasMany('SpekWeb\TelcoProduct', 'prd_group', 'prd_group');
}
}
Child Model
<?php
namespace SpekWeb;
use Illuminate\Database\Eloquent\Model;
class TelcoProduct extends Model
{
public $table = 'telco_product';
public $primaryKey = 'tel_prd';
}
And this is My Controller
<?php
namespace SpekWeb\Http\Controllers;
use Illuminate\Http\Request;
use SpekWeb\Http\Requests;
use SpekWeb\Http\Controllers\Controller;
use SpekWeb\ProdukGroup;
use SpekWeb\TelcoProduct;
class ProdukController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$memberPrices = ProdukGroup::with(array(
'telcoProduct' => function($tpJoin) {
$tpJoin->join('wd_productprice','telco_product.tel_prd','=','wd_productprice.tel_prd');
$tpJoin->where('charge','>=',0);
$tpJoin->whereMemType('1'); //variabel
$tpJoin->where(function($qWhere) {
$qWhere->whereKodeKec('ASTAY'); //variabel
$qWhere->orWhereNull('cluster_gid');
});
},
)
)
->has('telcoProduct')
->get();
return $memberPrices;
}
}
I want the master record not showing when I filtered the code within 'with' area, using ->has('telcoProduct) still not working for me. The master record still showing on Blade Views. Is there any trick to solve this problems ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire