query-builder

Laravel : advanced search form query

杀马特。学长 韩版系。学妹 提交于 2021-02-18 08:35:54
问题 I have an advanced search form to filter out results from a database using Laravel. The data is filtered correctly but I have a requirement for the user to be able to filter by first name or last name using the same text box (in the advanced form). I tried orWhere to make sure it filters the name field with the first name or last name but the orWhere doesn't consider the other filters. The code I am using is as follows: DB::table('mytable') ->where(function($query) use ($name, $degree_s,

Laravel : advanced search form query

限于喜欢 提交于 2021-02-18 08:35:32
问题 I have an advanced search form to filter out results from a database using Laravel. The data is filtered correctly but I have a requirement for the user to be able to filter by first name or last name using the same text box (in the advanced form). I tried orWhere to make sure it filters the name field with the first name or last name but the orWhere doesn't consider the other filters. The code I am using is as follows: DB::table('mytable') ->where(function($query) use ($name, $degree_s,

Query builder get array of results instead of objects in Laravel

一个人想着一个人 提交于 2021-02-05 07:10:46
问题 Here's my query DB::table('genres') ->join('albumGenres', 'genres.id', '=', 'albumGenres.genre_id') ->join('albums', 'albumGenres.album_id', '=', 'albums.id' ) ->select('genres.id') ->where('albumGenres.album_id','=',$this->id)->get(); But I get something like this "genre_id": [ { "id": "4" }, { "id": "8" } ] What should I do to get the results as just an array "genre_id" : [4,8] 回答1: With new versions of Laravel, you should use pluck() instead of lists(). DB::table('genres') ->join(

Bookshelf.js - Nested relations while querying with andWhere()

99封情书 提交于 2021-01-29 11:11:35
问题 I'm using the strapi framework based on node.js and while creating a query-builder, I'm facing an issue with the andWhere() clause. I am implementing search functionality where a user can input some text in a form input field, which gets passed in, and database table fields are queried based on that text . In the code below, you can see that I query for two things: Search the product model wherever the text is present in the name field. And always check and search the product model wherever

CodeIgniter Subquery in Query Builder

拜拜、爱过 提交于 2021-01-29 06:19:43
问题 Is there a way or can someone translate this to code igniter query builder. SELECT result.id, result.name, result.added FROM (SELECT tbl.id, tbl.name, tbl.date_added FROM table tbl GROUP BY tbl.id) result GROUP BY result.date_added I already have my research(link below) but can't find anything like this(query above). https://www.codeigniter.com/userguide3/database/query_builder.html https://arjunphp.com/how-to-write-subqueries-in-codeigniter-active-record/ And yes, this can be done using

Search with concat fields in cakephp 3

感情迁移 提交于 2021-01-28 04:44:01
问题 I need to make a search query using $this->Paginate in CakePHP 3. Following is the code I am using $searchCondition = array( 'OR' => array( 'Quotes.quotenum LIKE' => "%" . $this->request->data['Quote']['keyword'] . "%", 'Branches.name LIKE' => '%' . $this->request->data['Quote']['keyword'] . '%', 'Contacts.fname LIKE' => '%' . $this->request->data['Quote']['keyword'] . '%', 'Contacts.lname LIKE' => '%' . $this->request->data['Quote']['keyword'] . '%', 'CONCAT(Contacts.fname, Contacts.lname)