【发布时间】:2016-06-28 19:33:47
【问题描述】:
如何在视图的连接中使用表的别名。我编写了以下连接查询
$show Data = DB::table('jobs_users')
->join('jobs', 'jobs_users.job_id', '=', 'jobs.id')
->join('users as u1', 'jobs_users.user_id', '=', 'u1.id')
->join('users as t1', 'jobs_users.trainer_id', '=', 't1.id')
->get();
我有两个表 Jobs 和 users,他们的 id 存储在数据透视表中。 在用户表中,我有用户培训师和用户学生。现在我想在视图中显示工作、学生和培训师的名称。我得到了工作、培训师的名字,但没有得到学生的名字。在一个视图中,我使用连接结果如下
@for each ($show Data as $u)
<TD>
{{$u->company Name}} // job name
</TD>
<TD>
{{$u ->user Name}} //trainer name
</TD>
<TD>
{{$u->user Name}}</TD> // student name
</tr>
@end for each
在拉拉维尔 5.2 用户表
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->integer('user_id')->unsigned()->null able();
$table->integer('user_type_id')->unsigned();
$table->en um('account Type',['Fresh', 'Professional'])->null able();
$table->string('user Name',30);
$table->string('email', 30)->unique();
$table->string('password',64);
$table->date('dob',30)->null able();
$table->en um('gender',['Male', 'Female']);
$table->string('country',30)->null able();
$table->string('city',15)->null able();
$table->string('mobile No', 15)->null able();//+92 42 5689896
$table->string('c n i c',60)->null able();
$table->string('address',512)->null able();
$table->string('degree Level',30)->null able();
$table->string('degree Title',30)->null able();
$table->string('institution',60)->null able();
$table->string('degree Country',60)->null able();
$table->string('degree City',60)->null able();
$table->string('experience')->null able();;
$table->unsigned Small Integer('work Experience')->null able();
$table->string('industry', 60)->null able();
$table->string('aced Country',30)->null able();
$table->string('c v',30)->null able();
$table->remember Token();
$table->time stamps();
$table->soft Deletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
【问题讨论】:
-
您也可以发布您的数据库表吗?