Can someone help me with this problem?
I have 2 tables in phpMyAdmin
the first one where the with the department_id of the person
The second one where you can see the department_id and then the department_name
I have a table with this code:
<div class="container">
<table class="table table-striped table-bordered">
<thead class="table-dark">
<tr>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Department Name</th>
</tr>
</thead>
<tbody>
@foreach ($employee as $name)
<tr>
<td>{{ $name->first_name }}</td>
<td>{{ $name->last_name }}</td>
<td>{{ $name->!!!IDK YET!!! }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
Basically, for each employee I want to grab the department_id and check what the matching department_name
Extra code that makes the table on my page work:
EmployeeController.php
<?php
namespace App\Http\Controllers;
use App\Models\Employee;
use Illuminate\Http\Request;
class EmployeeController extends Controller
{
public function index()
{
$employee = Employee::all();
return view('employee.index', compact('employee'));
}
}
Employee.php (Model)
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Employee extends Model
{
use HasFactory;
protected $employees = 'employees';
protected $EmployeeValues = ['first_name','last_name'];
protected $departments = 'departments';
protected $DepartmentValues = ['department_id','department_name'];
}