Can anyone help me understand why $applications is unset after every call to sendReviewRequest?
class Reviews extends Component
{
public $name;
public $applications;
public function updatedName()
{
if (strlen($this->name) > 2) {
$profileIds = auth()->user()->profiles()->active()->pluck('id')->toArray();
$this->applications = Application::whereIn('profile_id', $profileIds)
->join('users', 'users.id', '=', 'applications.user_id')
->where('users.firstname', 'LIKE', '%'.$this->name.'%')
->has('messages', '>', 1)->get();
}
}
public function render()
{
return view('livewire.member.reviews')
->layout('layouts.member');
}
public function sendReviewRequest($userId, $profileId)
{
foreach ($this->applications as $application) {
if ($application->user_id == $userId && $application->profile_id == $profileId) {
$reviewRequest = new ReviewRequest();
$reviewRequest->user_id = $userId;
$reviewRequest->profile_id = $profileId;
$reviewRequest->sent_at = Carbon::now();
$reviewRequest->hash = Str::orderedUuid()->toString();
$reviewRequest->save();
break;
}
}
}
}