Last active
February 27, 2018 18:25
-
-
Save tisuchi/64a7b69a73f8d88ac1cc991a992c58cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class StoreOffer extends Model | |
| { | |
| public function store() | |
| { | |
| return $this->belongsTo('App\Models\Store', 'store_id', 'store_id'); | |
| } | |
| public function category() | |
| { | |
| return $this->belongsTo('App\Models\Category', 'category_id', 'category_id'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Transaction extends Model | |
| { | |
| public function user() | |
| { | |
| return $this->belongsTo('App\Models\User', 'user_id', 'user_id'); | |
| } | |
| public function offer() | |
| { | |
| return $this->belongsTo('App\Models\StoreOffer', 'offer_id', 'offer_id'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| public function getTransaction(){ | |
| $transaction_detail = Transaction::with(['user','offer'])->where('status', 1)->get(); | |
| return $transaction_detail; | |
| } |
Author
laravel 5.5
Transaction::with(['user','offer'])->where('status', 1)->get();
this query returns empty array
if i use
return $this->belongsTo('App\Models\StoreOffer', 'offer_id', 'offer_id')->with(['store', 'category']);
instead of using
return $this->belongsTo('App\Models\StoreOffer', 'offer_id', 'offer_id');
in my Transaction Model....
without where clause this query returns
[{
"transaction_id": 1,
"user_id": 1,
"offer_id": 1,
"amount": "2.0",
"status": 1,
"created_at": "2018-02-27 11:02:45",
"users": {
"user_id": 1,
"first_name": "sunny",
"last_name": "abc",
"email": "bsjs@hjjs.dn",
"password": "",
"phone_number": "0xxxxx1789",
"type": 1,
"access_token": "MTUx2aTcxNjI2Mw==",
"image": null,
"created_at": "2018-02-27 07:24:23",
"updated_at": null
},
"offer": {
"offer_id": 1,
"store_id": 1,
"category_id": 1,
"offer": "Hello a offer from jodu",
"endDate": "2018-02-22 10:24:00",
"created_at": null,
"updated_at": null,
"store": {
"store_id": 1,
"store_name": "BD Wireless",
"store_image_url": "images/store/bd_wireless.png",
"created_at": null,
"updated_at": null
},
"category": {
"category_id": 1,
"category_name": "Recharge",
"total_offer": 1,
"created_at": null,
"updated_at": null
}
}
}]
which is expected ... and with where clause it returns
[]
i need to filter the Transaction data based of status flag.
which is not happening.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By the way, which laravel version you are using for?