0

In my Laravel 5.8, I have this query:

use DB;

    $published_goalss = DB::table('hr_employees e')
                ->join('hr_employees em','em.employee_code','=','e.line_manager_id')
                ->join('hr_departments d','e.department_id','=','d.id')
                ->join('hr_employees eh','eh.employee_code','=','d.dept_head')
                ->join('hr_employees eb','eb.employee_code','=','d.hr_business_partner_id')
                ->join('appraisal_goals ag','ag.company_id','=','e.company_id')
                 ->select(
                    'e.employee_code as staff_id',
                    DB::raw('CONCAT(e.first_name, " ", e.last_name) AS full_name'),
                    DB::raw('CONCAT(hr_employees.first_name, " ", hr_employees.last_name) AS full_name'),
                    DB::raw('IF(hr_employees.gender_code = 0, "Female", "Male") AS gender'),
                    'hr_employee.email as official_email',
                    DB::raw('CONCAT(eh.first_name, " ", eh.last_name) AS hod_name'),
                    DB::raw('CONCAT(eb.first_name, " ", eb.last_name) AS hrbp_name'),
                    DB::raw('(CASE WHEN ag.is_approved = 3 THEN "Approved" WHEN ag.is_approved = 2 THEN "Not Approved" WHEN ag.is_approved = 1 THEN "Awaiting Approval" ELSE "Draft" END) AS goal_status')
             )
                ->where('e.employee_code', $publishedgoals)
                ->where('e.company_id', $userCompany)
                ->where('e.hr_status', 0)                
            ->get();

When I ran it, I got this error:

Base table or view not found: 1146 Table 'myapp.hr_employees e' doesn't exist

But the table exists.

I am using XAMPP

How do I resolve this?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
mikefolu
  • 1,203
  • 6
  • 24
  • 57
  • Have you defined the database of the app correctly in the laravel database configuration? If you log into the database and put `use myapp;` and `show tables;` does it list your `hr_employees` table? – user3647971 Jul 02 '20 at 20:51
  • @user3647971 - Yes, the table is there: hr_employees – mikefolu Jul 02 '20 at 21:01
  • 1
    You should alias your table differently: `DB::table('hr_employees AS e')...` as seen [here](https://stackoverflow.com/questions/17713730/how-to-alias-a-table-in-laravel-eloquent-queries-or-using-query-builder) – user3647971 Jul 02 '20 at 21:06

0 Answers0