I'm still learning laravel, tryed quite few different approch but I cannot for the life of post angularjs query to laravel and use the query like function
i did this which works but is quite ugly:
$parms = Input::only('search');
if($parms['search']){
$build='';
$i=0;
foreach($parms['search']['predicateObject'] as $k => $v){
foreach($v as $n => $r){
if($i >0) $build .=' AND ';
$build .="{$k}.{$n} LIKE '%{$r}%'";
$i++;
}
}
$response = DB::table('userinfo')
->select('userinfo.*', 'departments.DEPTNAME')
->join('departments', 'departments.deptid', '=', 'userinfo.DEFAULTDEPTID')
->whereRaw($build)
->paginate(Input::only('pagination')['pagination']['number']);
}else{
$response = DB::table('userinfo')
->select('userinfo.*', 'departments.DEPTNAME')
->join('departments', 'departments.deptid', '=', 'userinfo.DEFAULTDEPTID')
->paginate(Input::only('pagination')['pagination']['number']);
}
return response()->json($response);
here is the array
Array ( [userinfo] => Array ( [USERID] => 120 [NAME] => james ) )
userinfo is the table name USERID is the column name
eg.
$build .="userinfo.USERID LIKE '%120%' AND userinfo.NAME LIKE '%james%'";
if your wondering why am i sending the table and column name in diffrent array value, that's how angular is sending it over
input example:
<input st-search="userinfo.NAME" class="form-control" />
thank you for looking..
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TXmJpg
via IFTTT
Aucun commentaire:
Enregistrer un commentaire