I need one more ->Where and ->orderBy and ->limit in my below eloquent query.
value for these fiels should come from below php variable code
i want to add these (where,orderby,limit) in sql query some thing like below
->where = $where
->orderBy = $order_by
->limit = $offset,$page_size.
$offset=4;
$page_size=5
if (isset($query_array['training_center_name'])) {
$trainingCenter = $query_array['training_center_name'];
$where .= " AND user_organizations.organization_name = '$trainingCenter'";
}
$order_by = " ORDER BY user_template.update_date DESC";
if (isset($query_array['order-by'])) {
$field_order = explode(',', $query_array['order-by']);
if ($field_order[0] == 'area') {
$order_by = " ORDER BY user_template.area $field_order[1]";
} elseif ($field_order[0] == "center_name") {
$order_by = " ORDER BY user_organizations.organization_name $field_order[1]";
} else {
$order_by = " ORDER BY user_template.$field_order[0] $field_order[1]";
}
}
$query = UserTemplateModel:: Select('user_template.org_id'')
->join('user_organizations', 'user_template.org_id', 'user_organizations.org_id')
->join('user_organization_users', 'user_organizations.org_id', 'user_organization_users.org_id')
->where('user_organization_users.user_id',$userId)
->where('user_template.status',ACTIVE)
->get();
$query_result = $query->toArray();
return $query_result;
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2YkCv8X
via IFTTT
Aucun commentaire:
Enregistrer un commentaire