Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Laravel Eloquent select where latest equal to value

I have two MySQL tables, the second table recorded the states of an attribute of the first table, I need to get all the records of the first table where the last state of the attribute is equal to value, how to do it with eloquent ?

here is my code that I need to add the condition to :

    //Materiels table1
    //Journal_etat_materiels table2

    function getMaterielForAff(Request $request)
    {
        $data = Materiel::join('Types', 'Materiels.type_id', '=', 'Types.type_id')
                ->join('Users', 'Materiels.user_id', '=', 'Users.id')
                ->join('Journal_etat_materiels', 'Materiels.mat_code', '=', 'Journal_etat_materiels.mat_code')
                ->select(
                    'Materiels.id',
                    'Materiels.mat_code',
                    'Materiels.mat_designation',
                    'Materiels.mat_ns',
                    'Materiels.imei1',
                    'Materiels.imei2',
                    'Types.type_designation',
                    'Materiels.mat_description',
                    'Materiels.mat_carac',
                    'Materiels.note',
                    'Users.username',
                    'Materiels.mat_date'
                )
                ->whereNotIn('Materiels.mat_code', explode(' ', $request->mat_codes));

        return DataTables::of($data)
            ->addColumn('check', function ($check) {
                return '<input type="checkbox" required="required" name="check" class="check" id="' . $check->id . ' value="' . $check->id . '">';
            })
            ->rawColumns(['check'])
            ->make(true);
    }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!