public function getIndex()
{
$posts = DB::table("users")
->orderBy('id', 'desc')
->select("users.id","users.created_at","companies.name as nama_companies","users.privilege_type","users.name","users.name","users.email","users.password")
->join("companies","companies.created_at","=","users.id_kategori","companies.photo")
->paginate(5);
return view('users',['posts'=>$posts]);
}

请帮助我,谢谢
答案 0 :(得分:0)
试试此代码
$posts = User::join('companies', 'companies.name', '=', 'users.name')
->orderBy('user.id', 'desc')
->select(array("users.id","users.created_at","companies.name as nama_companies","users.privilege_type","users.name","users.name","users.email","users.password"))->paginate(5);
答案 1 :(得分:0)
查看https://laravel.com/docs/5.1/queries#joins
上的文档例如,用条件和运算符替换方括号。
->join("companies", "id_companies", "=" , "companies.id")
您的代码看起来像..
$posts = DB::table("users")
->select("users.id",
"users.created_at",
"companies.name as nama_companies",
"users.privilege_type",
"users.name",
"users.email",
"users.password")
->join("companies", [ ColumnName ], [Condition] , [ColumnName]) //replace square brackets..
->orderBy('id', 'desc')
->paginate(5);