私は1つの問題に直面しています。誰もがまず、私は今、私はリストモデルlaravel 5.2で複数の関連テーブルを条件付ける方法012
2)(Listing.php)
今enter code here
public function topservices(){
return $this->hasMany('App\Sellerprofile','list_id');
}
を2つのモデル
1)User.php
enter code here
public function listings(){
return $this->hasOne('App\Listing','user_id')
->with("topservices");
}
を持っている 私を助けることができます私は1つの機能を持っています
enter code here
public function nails(){
$users = DB::table('users')
->where(['service_name'=>"Seller"])
->get();
$users = json_decode(json_encode($users),true);
foreach($users as $alluser){
$ids[] = $alluser['id'];
}
if(!empty($ids)){
$allData = User::with('listings')->whereIn('id',$ids)->get();
$allData = json_decode(json_encode($allData),true);
echo "<pre>"; print_r($allData); die; ///when i print this array it gives me below output
}
$title = "Nails";
return view("listings.listing",['allData'=>$allData,'title'=>$title]);
}
出力:
enter code here
Array
(
[0] => Array
(
[id] => 1
[title] => Mr
[firstname] => kunal
[email] => [email protected]
[listings] => Array
(
[id] => 1
[user_id] => 1
[type] => premimum
[business_name] => kunal
[topservices] => Array
(
[0] => Array
(
[id] => 5
[service_id] => 1
[list_id] => 1
[name] => Acrylic
[duration] => 10mins
[price] => 10
)
[1] => Array
(
[id] => 6
[service_id] => 2
[list_id] => 1
[name] => Hair Top
[duration] => 30mins
[price] => 20
)
[2] => Array
(
[id] => 7
[service_id] => 3
[list_id] => 1
[name] => Skin Care Top
[duration] => 1hr-30mins
[price] => 30
)
[3] => Array
(
[id] => 8
[service_id] => 4
[list_id] => 1
[name] => Massage Top
[duration] => 20mins
[price] => 50
)
)
)
)
[1] => Array
(
[id] => 2
[title] => Mr
[firstname] => kunal
[email] => [email protected]
[listings] => Array
(
[id] => 2
[user_id] => 2
[type] => premimum
[topservices] => Array
(
[0] => Array
(
[id] => 9
[service_id] => 6
[list_id] => 2
[name] => Acrylic
[duration] => 30mins
[price] => 10
)
[1] => Array
(
[id] => 10
[service_id] => 6
[list_id] => 2
[name] => Powder gel nails
[duration] => 45mins
[price] => 20
)
[2] => Array
(
[id] => 11
[service_id] => 6
[list_id] => 2
[name] => Polish change
[duration] => 10mins
[price] => 25
)
[3] => Array
(
[id] => 12
[service_id] => 6
[list_id] => 2
[name] => Hand design
[duration] => 2hrs
[price] => 100
)
[4] => Array
(
[id] => 13
[service_id] => 7
[list_id] => 2
[name] => Hair Top
[duration] => 30mins
[price] => 200
)
)
)
)
)
今、あなたは出力の上に見られ、私は価格10 =より大きく、 30未満等しい私の予想出力があるtopservicesの下にあるすべてのものを配列したいTopservices配列があります: -
は、enter code here
Array
(
[0] => Array
(
[id] => 1
[title] => Mr
[firstname] => kunal
[email] => [email protected]
[listings] => Array
(
[id] => 1
[user_id] => 1
[type] => premimum
[business_name] => kunal
[topservices] => Array
(
[0] => Array
(
[id] => 5
[service_id] => 1
[list_id] => 1
[name] => Acrylic
[duration] => 10mins
[price] => 10
)
[1] => Array
(
[id] => 6
[service_id] => 2
[list_id] => 1
[name] => Hair Top
[duration] => 30mins
[price] => 20
)
)
)
)
[1] => Array
(
[id] => 2
[title] => Mr
[firstname] => kunal
[email] => [email protected]
[listings] => Array
(
[id] => 2
[user_id] => 2
[type] => premimum
[topservices] => Array
(
[0] => Array
(
[id] => 9
[service_id] => 6
[list_id] => 2
[name] => Acrylic
[duration] => 30mins
[price] => 10
)
[1] => Array
(
[id] => 10
[service_id] => 6
[list_id] => 2
[name] => Powder gel nails
[duration] => 45mins
[price] => 20
)
[2] => Array
(
[id] => 11
[service_id] => 6
[list_id] => 2
[name] => Polish change
[duration] => 10mins
[price] => 25
)
)
)
)
)
誰でも助けてくれますか?事前に感謝します。私は釘機能で何をしますか
は、そのは私にエラーを与えて@jaysingkar動作していない()(爆発パラメータ2が文字列であることを期待し、オブジェクトが、指定された):( – kunal
はあなたがwhereBetween価格欄に価格を使用して一覧表にされていないことがありますそれは私にエラーが発生します(SQLの場合、 'listing'.user_id' in(1,2)および 'price'は10から30までです) – kunal