In Laravel 9, an error is reported: call to undefined method Illuminate\\http\resources\MissingValue::isEmpty()
1. In Laravel 9, an error is reported: call to undefined method illuminate\\http\\resources\\missingValue::isempty(). as shown in Figure 1
2. Check the code implementation
if ($this->whenLoaded('customTagsEnable')->isEmpty()) {
return [];
}
3. Print $this->whenloaded(Customtagsenable), the result is as follows, which are the results of the resource after the model association is not loaded, and the resource after the model association is loaded
object(Illuminate\Http\Resources\MissingValue)#4330 (0) {
}
object(Illuminate\Database\Eloquent\Collection)#4177 (2) {
["items":protected]=>
array(0) {
}
["escapeWhenCastingToString":protected]=>
bool(false)
}
4. Re-implement the following, no more errors
use Illuminate\Http\Resources\MissingValue;
if ($this->whenLoaded('customTagsEnable') instanceof MissingValue) {
return [];
}
