query-builder

How to write select query with subquery using laravel Eloquent Querybuilder?

孤街浪徒 提交于 2019-11-30 16:12:59
I had got the result from the query. My Simple SQL is: SELECT o2.driver_id, total_delieveries, DATE_FORMAT(o1.created_at ,'%Y-%m-%d') AS created_at FROM ( SELECT driver_id, created_at, COUNT(driver_id) AS total_delieveries FROM orders WHERE is_paid = 0 AND order_status = 5 AND created_at BETWEEN "'.$first_Day.'" AND "'.$last_Day.'" GROUP BY DATE_FORMAT(created_at ,'%Y-%m-%d'),driver_id ) o1 INNER JOIN orders o2 ON o1.driver_id = o2.driver_id GROUP BY o1.created_at In Laravel source, I wrote the query: $responseData = DB::select(DB::raw('select t.driver_id,total_delieveries,DATE_FORMAT(q1

AngularJS Query Builder similar to http://redquerybuilder.appspot.com/ [closed]

北战南征 提交于 2019-11-30 14:43:14
I am trying to create a complete query builder with AngularJS only. I have seen http://redquerybuilder.appspot.com/ which is awesome but not with AngularJS and I would like to create in AngularJS. Can you please advise if it is already available or the some help because query branching would be nested. Maybe this is what you are looking for: http://niklr.github.io/angular-query-builder/ It is similar to the query builder of mfauveau but with additional features such as: Autocomplete based on selected options implemented with Bootstrap's typeahead plugin. Dynamic source fields based on selected

Query builder not inserting timestamps

偶尔善良 提交于 2019-11-30 14:33:37
问题 I am using Query builder to insert data all fields are been inserted but timestamps like created_at and updated_at are not inserting they all have default 0:0:0 values my insert query is $id = DB::table('widgets') ->insertGetId(array( 'creator' => Auth::user()->id, 'widget_name' => $request->input('widget_name'), 'pages' => json_encode($request->input('pages')), 'domain' => $request->input('domain'), "settings" => $settings, )); 回答1: All right. Fields created_at , update_at and deleted_at are

Query builder not inserting timestamps

喜夏-厌秋 提交于 2019-11-30 11:01:17
I am using Query builder to insert data all fields are been inserted but timestamps like created_at and updated_at are not inserting they all have default 0:0:0 values my insert query is $id = DB::table('widgets') ->insertGetId(array( 'creator' => Auth::user()->id, 'widget_name' => $request->input('widget_name'), 'pages' => json_encode($request->input('pages')), 'domain' => $request->input('domain'), "settings" => $settings, )); All right. Fields created_at , update_at and deleted_at are "part" of Eloquent . You use Query Builder => inserting doesn't affect on these two fields ( created_at and

symfony2 form querybuilder with parameters

╄→гoц情女王★ 提交于 2019-11-30 08:04:05
I want to put my entity in the function of the query builder: ->add( 'weeks', 'entity', array( 'class' => 'MV\CaravanBundle\Entity\CaravanRow', 'property' => 'line', 'query_builder' => function(EntityRepository $er ) use ( $caravan ) { return $er->createQueryBuilder('w') ->orderBy('w.dateFrom', 'ASC') ->where('w.caravan = ?', $caravan ) ->andWhere('w.visible = 1') ->andWhere('w.booked = 0'); } but get the message: Expression of type 'Entity\Name' not allowed in this context So what is the (best) way to give the querybuilder information. You should set the parameter separately like so: ->add(

Laravel query builder - re-use query with amended where statement

限于喜欢 提交于 2019-11-30 08:02:11
My application dynamically builds and runs complex queries to generate reports. In some instances I need to get multiple, somewhat arbitrary date ranges, with all other parameters the same. So my code builds the query with a bunch of joins, wheres, sorts, limits etc and then runs the query. What I then want to do is jump into the Builder object and change the where clauses which define the date range to be queried. So far, I have made it so that the date range is setup before any other wheres and then tried to manually change the value in the relevant attribute of the wheres array. Like this;

Using JOIN in Symfony2/Doctrine SQL

谁说胖子不能爱 提交于 2019-11-30 06:46:27
I have a problem while trying to USE QueryBuilder OR DQL. I have the following relation: User <-1:n-> Profile <-n:m-> RouteGroup <-1:n-> Route I would like to make a DQL that lists all the routes that a specific user has access. I can get this information with the following code: $usr = $this->container->get('security.context')->getToken()->getUser(); foreach ($usr->getProfiles() as $profile){ foreach ($profile->getRoutegroups() as $routegroup){ var_dump($routegroup->getRoutes()->toArray()); } } For obvious reason i cant use this code, otherwise I will overload my server, LOL. I tried the

Query with EXISTS for Doctrine Symfony2

社会主义新天地 提交于 2019-11-30 05:56:40
问题 How can I implement the following query with Query Builder? SELECT * FROM t WHERE t.status = 1 OR EXISTS(SELECT * FROM r WHERE r.t_id = t.id AND r.status = 1 ) The part without exist check is easy, but is there a way to implement the EXISTS ? 回答1: You either need to use two query builders: $queryBuilder->expr()->exists($subQueryBuilder->getDql()); or use DQL directly: $queryBuilder->expr()->exists('SELECT * FROM r WHERE r.t_id = t.id AND r.status = 1' ); You'll find more examples in the docs:

laravel search multiple words separated by space

元气小坏坏 提交于 2019-11-30 05:08:30
I am new to laravel query builder, I want to search multiple words entered in an input field for example if I type "jhon doe" I want to get any column that contains jhon or doe I have seen/tried solutions using php MySQL but can't able to adapt to query builder //1. exploding the space between the keywords //2. using foreach apend the query together $query = "select * from users where"; $keywordRaw = "jhon doe"; $keywords = explode(' ', $keywordRaw ); foreach ($keywords as $keyword){ $query.= " first_name LIKE '%" + $keyword +"%' OR "; } how do I do this using query builder this is what i have

Laravel Query Builder WHERE NOT IN

只谈情不闲聊 提交于 2019-11-30 04:42:32
问题 I have the following sql query SELECT * FROM exams WHERE exams.id NOT IN (SELECT examId FROM testresults) how can I convert it into Laravel query builder format? Thanks. 回答1: You can use whereNotIn with a closure: $result = DB::table('exams')->whereNotIn('id', function($q){ $q->select('examId')->from('testresults'); })->get(); 来源: https://stackoverflow.com/questions/28361461/laravel-query-builder-where-not-in