When I display the name of table using the id of another table in Laravel I declare like this. But when I want to get the id to edit, the error is like the title. Please help me, I am very grateful.
Controller
public function manage_departments(){
$manage_departments=DB::table('departments')
->join('faculties','faculties.id','=','departments.faculty_id')
->orderBy('departments.created_at','desc')->get();
$all_manage_departments=view('admin.manage-departments')->with('manage_departments', $manage_departments);
return view('layouts.master')->with('admin.manage-departments', $all_manage_departments);
}
You don't have select
in your query builder. As laravel doc said, you can specify what do you want to select in select
method. I select faculties.id
and departments.id
for example.
DB::table('departments')
->select('faculties.id','departments.id')
->join('faculties','faculties.id','=','departments.faculty_id')
->orderBy('departments.created_at','desc')->get();