Category : sql

I have a column start_time of type date and a column duration_temp of type Integer and I made a new column duration of type timestamp I want to fill duration column with those values: only the date without hours, minutes and seconds from start_time and add the value of "duration_temp" as minutes to this date. ..

Read more

I am trying to insert data to a pivot table order_serrvice using arrays I follow this code: https://blog.quickadminpanel.com/master-detail-form-in-laravel-jquery-create-order-with-products/ OrderController: $order= Order::create($data); $services = $request->input(‘services’, []); $quantities = $request->input(‘quantities’, []); for ($service=0; $service < count($services); $service++) { if ($services[$service] != ”) { $order->services()->attach($services[$service], [‘quantity’ => $quantities[$service]]); } } the Blade Page: <tbody> <tr id=’addr0′> <td>1</td> <td> ..

Read more

I have a model Survey which is related to hasOne another model Installation which is related to hasMany another model Assignment. So i defined a hasManyThrough relationship like this public function assignments() { return $this->hasManyThrough(Assignment::class,Installation::class); } I want to write a query to fetch any Survey where the Assignments associated with the survey does not ..

Read more

Hi respected community members, I am trying a query to fetch records from two tables and order by the latest record but still no luck. Basically, I have two tables. one is donations and second one is recurring_donation_invoices.donations table have a field type which can be onetime or recurring.if the donation is of type onetime ..

Read more

Good Day, I do have 2 tables loan_account_installment and loan_account_installment_repayment related to each other. If repayment was made row will be created at loan_account_installment_repayment. What I want to happen is to deduct the payment made on loan_account_installment_repayment on loan_account_installment table. Unfortunately Im having an error. Call to undefined method stdClass::update(). By the way this is ..

Read more

ErrorException Undefined index: service_id I Creat an application that has an order the order_services table is a pivot table of orders and services I dont know from whare I take the index service ID and how can I fix this issue?? here is the code: Order Controller $order= Order::create($data); $services[] = $request->serviceOrders; if ($request->serviceOrders) { ..

Read more

I have a categories table where categories have a parent mentioned within same table as in below screenshot I want to implement self join in Laravel using Eloquent where parent category is mentioned in a saperate col: Raw Sql Query: DB::select("SELECT c.id, c.name, parents.name AS `Parent Category Name` FROM product_categories AS c LEFT JOIN product_categories ..

Read more

I’m a front-end dev who ended up having to work on backend. I know Node but this is Laravel 5.5. Anyways, I’m making a query to retrieve runs, looking like this return $runs = DB::table(‘runs’) ->join(‘users’, ‘runs.user_id’, ‘=’, ‘users.id’) ->join(‘statuts’, ‘runs.statut_id’, ‘=’, ‘statuts.id’) ->join(‘machines’, ‘runs.machine_id’, ‘=’, ‘machines.id’) ->join(‘projet_run’, ‘runs.id’, ‘=’, ‘projet_run.run_id’) ->join(‘projets’, ‘projet_run.projet_id’, ‘=’, ‘projets.id’) ..

Read more

I can’t wrap my head around this. I have three tables (abbreviated): *images* id | label | … *keywords* id | label | … *image_keyword* image_id | keyword_id And I have their many to many relations defined in the models: *Image.php* public function keywords() { return $this->belongsToMany(Keyword::Class); } *Keyword.php* public function images() { return $this->belongsToMany(Image::Class); } At one point I ..

Read more

I have multiple tables, which all hold different transaction data, here is an example: $q1 = DB::connection(‘mysql_live’)->table(‘transactions_vk’)->where(‘user_id’, $userid)->where(‘amount’, ‘!=’, ‘0’)->where(‘payed’, ‘Yes’) ->select(‘type’, ‘id’, ‘package’, ‘payed’, ‘amount’, ‘date_modified as date_added’, ‘payed as chargeid’)->get(); $q2 = DB::connection(‘mysql_live’)->table(‘transactions_stripe’)->where(‘user_id’, $userid)->where(‘amount’, ‘!=’, ‘0’)->where(‘payed’, ‘Yes’) ->select(‘type’, ‘id’, ‘package’, ‘payed’, ‘amount’, ‘date_added’, ‘charge_id as chargeid’)->get(); $total1 = $q1->merge($q2); I query them all ..

Read more

I have been trying to install a system to my local MAC via MAMP, I just recently updated the Database connection not configured error but not upon making the changes to the right configuration I got another error SQLSTATE[HY000] [2002] Connection refused. Error goes as follows : SQLSTATE[HY000] [2002] Connection refused (SQL: select active_template from ..

Read more

Currently working on getting my head around the ordering of things, not even with laravel at first, but sql. Though the end goal is to use eloquent. There are 2 conditions for the rows that need to be excluded. If I’m fetching the rows from TableA.. 1) TableA with the column status_id (or TableC.id) has ..

Read more

the product will be added into the cart but cart due to image error the card will not be shown. Here is my cart.blade.php file. @foreach(Cart::instance(‘cart’)->content() as $item) <li class="pr-cart-item"> <div class="product-image"> <figure><img src="{{asset(‘assets/images/products’)}}/{{$item->model->image}}" alt="{{$item->model->name}}"></figure> </div> <div class="product-name"> <a class="link-to-product" href="{{route(‘product.details’,[‘slug’=>$item->model->slug])}}">{{$item->model->name}}</a> </div> <div class="price-field produtc-price"><p class="price">${{$item->model->regular_price}}</p></div> <div class="quantity"> <div class="quantity-input"> <input type="text" name="product-quatity" value="{{$item->qty}}" data-max="120" ..

Read more

When I foreach all $data in my blade like @foreach($data as $d), when I use $d->text is returning the ‘text’ from the topics.text not from table replies.text public function ShowReplies($userid) { $data = DB::table(‘replies’)->join(‘topics’, ‘topics.id’, ‘=’, ‘replies.topic’)->where(‘topics.type’, ‘=’, 3)->where(‘replies.isPostDeleted’, ‘=’, 0)->where(‘replies.player’, ‘=’, $userid)->orderBy(‘replies.id’, ‘desc’)->get(); return view(‘replies’)->with(‘data’, $data); } Sourc..

Read more

I have a table with two date fields: reservation_begin booking_end I want to know the reservations that occupy me from August 25th to August 31st. In the select query I have: Booking::select (‘id’, ”name’, reservation_begin’, ‘reservation_end’) ->whereDate(‘reservation_begin’, ‘>=’, $startDate) ->whereDate(‘reservation_end’, ‘<=’, $endDate) ->get(); I will NOT find the record in the database if: $startDate = ..

Read more