Category : laravel-query-builder

We have a model called SentMessage and we have defined a relation called received_message_user (table: received_messages_users) on this model. There is another model called ReceivedMessage (table: received_messages_users) on which we have defined additional_info and list_member relations. For a particular id, let’s say 429189, we ran the following Laravel code. The time taken to execute it ..

Read more

Everything works on localhost but am getting error when I deploy on a live server. Can anyone help? CONTROLLER $status = Auth::guest() ? null : Request::where(‘person_id’, auth()->user()->persn[‘id’]) ->orderBy(‘id’,’DESC’)->limit(1)->get(); BLADE TEMPLATE @if(!empty(Auth::user()->persn->id) == !empty(Auth::user()->persn->req[0]->person_id) ) @foreach ($status as $statu) @if($statu->is_accepted == 1 && $statu->is_payed == 1) <a href=”#” class=”btn btn-success mr-3″ data-toggle=”modal” data-target=”#LoanReq”> <i class=”fas fa-paper-plane”></i> ..

Read more

I have a complex query:- $sql = "SELECT dateQ.selected_date, apiQ.no_of_error AS error FROM ( SELECT * from (SELECT adddate(‘1970-01-01’,t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from (SELECT 0 i UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT ..

Read more

I have this scenario where I have a array of string and the string values determine which query will be executed. And each execution returns different type of value that get pushed into another array. The simplified code is something like this: $results = []; $requests= [‘current’, ‘history’, ‘list’] foreach ($requests as $request) { if($request==’current’){ ..

Read more

I am getting a data array like this. This is like A is commenting in a file of the user. The query is getting all the comments for each user. array:3 [▼ 0 => {#1771 ▼ +"comments": "জরীপ প্রতিবেদন, মালিকানা বিবরনী, বিশ্লেষনী চিত্র ও ড্যাপের মতামতসহ নথি পেশ করুন।rn" +"created_at": "2019-03-27 18:07:11" +"ReviewerFullName": "mr Kamrul ..

Read more

I am getting a data array like this. This is like A is commenting in a file of the user. The query is getting all the comments for each user. array:3 [▼ 0 => {#1771 ▼ +"comments": "জরীপ প্রতিবেদন, মালিকানা বিবরনী, বিশ্লেষনী চিত্র ও ড্যাপের মতামতসহ নথি পেশ করুন।rn" +"created_at": "2019-03-27 18:07:11" +"ReviewerFullName": "mr Kamrul ..

Read more

I need to change my migration files because currently it’s using model but I’ve read that we should not be using models inside migration files. I have an eloquent code: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; use AppMyModel; class AddRelationshipIdToMyModel extends Migration { /** * Run the migrations. * * @return void */ public ..

Read more

Please the query first: $first = DB::table(‘account_payments as a’) ->leftJoin(‘labs’,’labs.id’, ‘=’, ‘a.lab_id’) ->select(DB::raw(‘NULL as id’), ‘a.narration as details’, DB::raw(‘NULL as airline’), DB::raw(‘NULL as sector’), ‘a.in as i’, ‘a.out as o’, ‘a.created_at’) ->whereBetween(DB::raw(‘DATE(a.created_at)’), [$start_date, $end_date]) ->where(‘a.lab_id’, ‘=’, $status); $datas = DB::table(‘journals as j’) ->leftJoin(‘labs as l’, ‘j.lab_id’, ‘=’, ‘l.id’) ->select(‘j.id’, ‘j.patient_name as details’, ‘j.airline’, ‘j.sector’, ‘j.lab_price ..

Read more

I have the below raw sql query which works as expected SELECT T1.category, T1.group, T1.series, T1.name, T2.cover FROM ( SELECT category, MAX(COALESCE(image)) as cover FROM stones GROUP BY `category` HAVING COUNT(DISTINCT category) = 1 ) T2 INNER JOIN stones T1 on T2.category = T1.category; While trying to convert it to Laravel Query Builder syntax, I ..

Read more

My Amenity Database column Store json_encode(array) data like this: column name amenity [{"key":"4MiZ54lNosCWc5VPCBa5uGBwrinFGC","value":"WI_FI"},{"key":"fuDn4n5gSMFJ5hCOOp445dh5Cmfc5g","value":"COMPLIMENTARY BREAKFAST"}…..] column name variable name $search_term My Search Term in Array Like this: [ "WI_FI", "TELEPHONE", "SWIMMING POOL" ] I try bun not work : $data->whereIn(‘amenity’,$search_term) Sourc..

Read more

I want to fetch user who has most points. I’ve two tables users and points. $top10pp = Points::orderBy(‘points’, ‘DESC’)->limit(10)->get(‘ppid’); I’m getting user id as per there points correctly by above query. Then I’m fetching the users by their user id that im getting in $top10pp variable. $psname = $this->getpp($top10pp); I’m calling a function to return ..

Read more

The structure of models/tables is: 1. ShopItem shopitem_id shopitem_title shopitem_price 2. Colours colour_id colour_name 3. ShopItemColours id shopitem_id (foreign key) colour_id (foreign key) I used query builder: $shopItems = ShopItem::where(‘shopitem_id’, 33) ->join(‘shop_item_colours’, ‘shop_item_colours.shop_item_id’, ‘=’, ‘shop_items.id’) ->join(‘colours’, ‘colours.colour_id’, ‘=’, ‘shop_item_colours.colours_id’) ->get(); Expected output is like this, where the ShopItemColours are an array. { ‘shopitem_id’: 33 ‘shopitem_title’: ..

Read more

I’m trying of get the product most selled of each community by the suppliers, However I’m getting always the product 1. My goal is only get one product "the most selled" according the community of the supplier. This is my db schema: And this is my current query using Laravel: $products = Purchase::select([ ‘purchases.supplier_id’, ‘purchases.id ..

Read more

I’m trying to use query builder in controller using laravel, and i don’t understand but the query didn’t find the data. Here’s the code: public function index() { $data = downloads::all(); if(request(‘searchName’)){ $data = $data->where(‘fileName’,’like’,’%’.request(‘searchName’).’%’); //Here’s the problem return view(‘download’, compact(‘data’)); } else{ return view(‘download’, compact(‘data’)); } } i already tried dd(request(‘searchName’)) and it display ..

Read more

I have models Like Event, Fields , Forms , FormAnswer, Event Columns are ‘name’,is_active ,start_date,end_date Fields event_id,field_name Forms name,email,dob,phone_number,event_id, Form_answer form_id,field_id,value User Create an Event and it has dynamic fields which go in the fields and some one fill it reponse and common fields go in the forms and dynamic answer goes in the form_answer ..

Read more