Laravel Join error "SQLSTATE[23000]: Integrity constraint violation"
error when join table in laravel.
my code is :
public function show($id)
{
try {
$idd = Sentry::getUser()->id;
$permit = Permit::join('users', 'permit.user_id', '=', 'users.id')
->where('permit.user_id', (int)$idd)
->select('users.id as uid','users.last_name','users.first_name','permit.id as pid', 'permit.user_id', 'permit.name', 'permit.sadere', 'permit.shenasname', 'permit.birth_date', 'permit.degree1', 'permit.field1'
, 'permit.university', 'permit.province', 'permit.eng_reg_num', 'permit.melli', 'permit.mobile', 'permit.phone', 'permit.postal_code'
, 'permit.address', 'permit.state', 'permit.created_at', 'permit.updated_at')
->find($id);
echo $permit->last_name;
//$permit = Permit::find($id);
$list = Permit::paginate(10);
$cites = DB::table('provinces')->get();
$evidence = Evidence::find($id);
return View::make('manager.admin_permit.show', compact('list', 'cites', 'evidence'))
->with('permit', $permit);
} catch (ModelNotFoundException $e) {
return Redirect::route('dashboard.admin.permit.index')->with('danger', 'درخواست معتبر نمیباشد.');
}
}
and get error :
QueryException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘id’ in where clause is ambiguous (SQL: select
users
.id
asuid
,users
.last_name
,users
.first_name
,permit
.id
aspid
,permit
.user_id
,permit
.name
,permit
.sadere
,permit
.shenasname
,permit
.birth_date
,permit
.degree1
,permit
.field1
,permit
.university
,permit
.province
,permit
.eng_reg_num
,permit
.melli
,permit
.mobile
,permit
.phone
,permit
.postal_code
,permit
.address
,permit
.state
,permit
.created_at
,permit
.updated_at
frompermit
inner joinusers
onpermit
.user_id
=users
.id
wherepermit
.user_id
= 1 andid
= 12 limit 1)
from Laravel Questions and Answers https://laravelquestions.com/php/laravel-join-error-sqlstate23000-integrity-constraint-violation/
via Lzo Media
No comments:
Post a Comment