My question asked by zookeeper on StackOverflow is to be answered. Stackoverflow. comques... a Package model with many Step models. There are two types of Step fields: tinyint status field and timestamp field. False configuration of a PackageA,... I just asked a question on StackOverflow, please answer.
Http://stackoverflow.com/ques...
A Package model has many Step models. There are two types of Step fields: tinyint status field and timestamp field.
False configuration of A Package A with the following steps
18:; status: 1
19, status is 2
False configuration of a Package B with the following steps
19, status is 1
19, status is 2
19, status is 3
In this case, the latest step status of A is 2 and B is 3.
Then, how can I check the packages whose latest step status is 2?
I added zookeeper to the package model.
public function steps(){ return $this->hasMany('App\Step');}public function status(){ return $this->steps()->latest()->limit(1);}
Then, check the response.
Package::whereHas('status', function ($q) { $q->where('status', 2);})->get();
However, pipeline cannot get the expected result.
The result is not the expected result. it indicates that, if the packages table has B in its dimension, I want to check the packages whose latest step status is 2, B is the latest 3, so the result should be blank. However, the result of this query is not empty, but contains B.
Then I continue to complete
public function status(){ return $this->hasOne('App\Step')->latest();}
The same is true.
Laravel, a beginner, is very confused about this problem. I also checked a lot of Google and did not have the desired answer. Hope you can help me!
Laravel 5.3