Attempting to join on a table and get a specific value, Laravel 6

Consider the following code sample. $lastMedicalRecord = $patient->medicalRecords->last()->join(‘medical_record_forms’, function ($join) { $join->on(‘medical_records.id’, ‘=’, ‘medical_record_forms.medical_record_id’) ->where(‘form_name’, ‘=’, ‘medical_treatment’) ->join(‘medical_record_field_values’, function ($join) { $join->on(‘medical_record_forms.id’, ‘=’, ‘medical_record_field_values.medical_record_form_id’) ->where(‘field’, ‘=’, ‘treatment_completed’); }); }); Because there could be tens of thousands of medical records what I am attempting to do is: Find all medical records for a patient and take…

Get count of span value in laravel

I retrieve data from the database as in controller: $users = DB::select(“select users.id, users.name, users.email, count(is_read) as unread from users LEFT JOIN messagesnews ON users.id = messagesnews.from and is_read = 0 and messagesnews.to = ” . Auth::id() . ” where users.id != ” . Auth::id() . ” group by users.id, users.name, users.email”); return view(‘admin.home.index’, compact(‘users’));…

Laravel set option to selected if option id is in an array list in blade view

I made query in my controller and send it to my blade : public function editContractorAssociation(DeveloperContractorAssociation $developer_contractor_association, Request $request) { $id = $request->id; $developer_contractor_association = DeveloperContractorAssociation::whereHas(‘defect_types’, function ($query) use($id) { $query->where(‘developer_contractor_associations.id’, $id); })->orwhereHas(‘contractor’, function ($query) use($id) { $query->where(‘developer_contractor_associations.id’, $id); })->first(); return view(‘dev-admin.contractors.associations.edit’, [‘developer_contractor_association’ => $developer_contractor_association]); } and when I call in my blade, I get…