Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0
$query = User::where(...)->where(...);
.
.
.
$query->skip(...)->take(...);
.
.
.
$query->orderBy(...);
.
.
.
return $query->get();

You could also find useful: http://laravel.com/docs/eloquent#query-scopes

Last updated 2 years ago.
0

have had done this way but

$query = self::take($userdata['per_page'])->skip($userdata['start']); this become compulsory to be call first and then

static function select($userdata = array()) { $userdata['start'] = $userdata['start'] ==''? 0 : $userdata['start'];

$query 		= self::take($userdata['per_page'])->skip($userdata['start']);

if(isset($userdata['searchtext']) && $userdata['searchtext'] != '' && $userdata['searchtext'] != 'no')
{
	$query->where('name', 'LIKE', "%".$userdata['searchtext']."%" )
		  -> where('email', 'LIKE', "%".$userdata['searchtext']."%" );
}

if($userdata['sorting_field'] != '' && $userdata['sorting_order'] != '')
{
	$query->orderBy($userdata['sorting_field'], $userdata['sorting_order']);
}
           

$result = $query->get();

// return remove_html_entities($result);
return $result;

}

THE ABOVE ONE IS WORKING FINE

static function select($userdata = array()) { $userdata['start'] = $userdata['start'] ==''? 0 : $userdata['start'];


i want something here so that i will get the instance instead of $query = User::where(...)->where(...); using this line so can use it in all of the condtition and satisfy all the if condition below.

$query	= .......... 

if($userdata['per_page'] > 0 && $userdata['start'] > 0)
{
	$query->take($userdata['per_page'])->skip($userdata['start']);
}

if(isset($userdata['searchtext']) && $userdata['searchtext'] != '' && $userdata['searchtext'] != 'no')
{
	$query->where('name', 'LIKE', "%".$userdata['searchtext']."%" )
		  -> where('email', 'LIKE', "%".$userdata['searchtext']."%" );
}

if($userdata['sorting_field'] != '' && $userdata['sorting_order'] != '')
{
	$query->orderBy($userdata['sorting_field'], $userdata['sorting_order']);
}
           

$result = $query->get();

// return remove_html_entities($result);
return $result;

}

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mukeshp004 mukeshp004 Joined 23 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.