php - Joins in Laravel and showing data in a view -


how use aliases of table use in joins in view.i write following join query

$show data = db::table('jobs_users')         ->join('jobs', 'jobs_users.job_id', '=', 'jobs.id')         ->join('users u1', 'jobs_users.user_id', '=', 'u1.id')         ->join('users t1', 'jobs_users.trainer_id', '=', 't1.id')         ->get(); 

i have 2 table jobs , users , ids stored in pivot table. in user table have user trainer , user student. want show name of job, student , trainer in view. getting name of job, trainer not getting name of student. in view use join result follows

@for each ($show data $u)     <td>         {{$u->company name}}   // job name     </td>     <td>         {{$u ->user name}}  //trainer name     </td>     <td>         {{$u->user name}}</td>   // student name     </tr> @end each 

in la ravel 5.2 user table

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 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 migrations.  *  * @return void  */ public function down() {     schema::drop('users'); } 

}

use select():

$showdata = db::table('jobs_users')         ->join('jobs', 'jobs_users.job_id', '=', 'jobs.id')         ->join('users u1', 'jobs_users.user_id', '=', 'u1.id')         ->join('users t1', 'jobs_users.trainer_id', '=', 't1.id')         ->select(<your other selects>, 'u1.name u_name', 't1.name t_name') //<- add other selects         ->get(); 

and display in views:

<td>      {{$u->u_name}} <!--trainer name--> </td> <td>      {{$u->t_name}} <!--student name--> </td> 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -