NicolasDiscuss NicolasDiscuss
8
I've been using Eloquent fine until recently when I try to group where clauses together for the first time and it's not working. $sql_message = Story::where('rating', $rating_list) ->where(function($query) {...
rhand rhand
11
When I use $project = Project::select(['id', 'subdomain']) ->where([ 'subdomain' => $subdomain, 'published' => true ]) ->first(); instead of $project = Project::where('subdomain...
rhand replied
Solved
Victor Alfonso Victor Alfonso
1
Hi folks, i got this morning with this problem, at the moment of execute a function that returns all the registered tickets on my table ticket_cors: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'estado_ticket' in where clause is ambig...
marosmjartan marosmjartan
7
Hello guys! I'm currently working on a code that requires a lot of eloquent logic. Many when clauses, many subquerries etc. you know... To clean up the code a bit, I want to use non-anonymous functions in subqueries instead of common anonymous funct...
Victor Alfonso Victor Alfonso
1
I would like to know how to handle this type of query in laravel, I am looking for the id of a record, but the only data I have of that record to be searched is the email, I share my code section //Here i get all the data of orders from woocommerce...
jeroenvanrensen jeroenvanrensen
2
Hi everyone, I'm new to joins and I created this query: select threads.*, count(replies.id) replies_count from threads where replies_count = 0 left join replies on replies.thread_id = threads.id group by threads.id How do I get this query into...
kramsuiluj kramsuiluj
1
I have 3 columns that I want to fill on my pivot table, I have "product_id", "size_id", and "price". I have no problem attaching the 2 ids but I don't know how I can attach another value into another column which in this...
grozavule grozavule
5
One of my models, ValidationError, saves two records for each object that I create, and I can't figure out why. This is all that I have in the ValidationError class: <?php namespace App; use Illuminate\Database\Eloquent\Model; class ValidationE...
Zaheer Zaheer
19
I can update a collection with following code : foreach ($rslt as $row) { $getacc = $acc->where('code',$row->code)->first(); $getacc->update(['clbal' => $row->total]); } This requires that clbal column must be present in $g...
martleby martleby
0
Hi, I have a couple of models Candidate and CandidateNumber. Candidate maps to a table and CandidateNumber maps to a database view. In Candidate I set a hasOne relationship to candidate number via CandidateID. I wrote an eloquent query to get Candida...
riccardo.t riccardo.t
0
For some reason I cannot get my relationship that is defined using a one-to-many morph relationship to eager load when using route model binding in a delete endpoint. It works fine in a put endpoint. I have no idea if the type of endpoint is actually...
sagar03d sagar03d
1
How to access belongTo relation inside whereHas condition? I've hasmany condition , inside which I need to access belongsTo relation of the that hasmany table...
tonyniu tonyniu
3
really confused about the class naming on the 'support' folder, always have the same name with other classes. Now what I am trying to do is: $some = (\Illuminate\Database\Eloquent\Collection::make(Session::get('cart')['wishlist']))::all(); I tried to...
User1980 User1980
15
Hi, I have this query: $users = DB::table('users') ->leftjoin('games', 'games.id', '=', 'games.user_id') ->select( DB::raw("count(games.*) AS active_games WHERE status='active'"),...
tylernathanreed tylernathanreed
16
While I understand the power of Polymorphism, I also understand the basic design principles for Database Design. Polymorphism violates something I consider to be crucial to Database Design: Foreign Key Relationships. When using Polymorphism, the two...
Chris1989 Chris1989
4
Hi i have two tables charges and customers(foreign) is it possible to make additional select to for table customers to get name ? as you can see inserted the join(commented) but cant find the way to make second select on the same query, i get error....
User1980 User1980
4
Hi all, I am trying to return the completed and pending sales of each active user in a single table. But I cannot work out how to do a count while returning the collection. Right now this returns the collection correctly $results= User::with('sales')...
rafaeladi rafaeladi
4
So i want to retrieve a collection of data from my DB but i only want to display the latest data. I already tried using latest() but it retrieved all of my results, not only the latest from a day for example. I want to have this because i want to use...
signet_planet signet_planet
0
Laravel supports simple "nested" database transactions but nested child transaction are always dependent on a parent transaction. If a parent transaction is rolled back so are the child ones even if they were already committed. Postgres and...
TerrePorter TerrePorter
2
I have this code: $r = Subscription::where('start_date', '>=', DB::raw('curdate()')) ->where('expire_date', '<', DB::raw('curdate()')) ->whereNotNull('start_date')...
Rymercyble Rymercyble
2
Hello, I have model item which has many to many relationship to itself and it also has multiple layers - item can be crafted from another item which is crafted from another item and so on currently i'm using protected $with = ['items']; public funct...
jdillon jdillon
2
My application has the following entities: Locations, Disciplines, Instructors Disciplines and Instructors should be a many to many relationship, so in my Discipline model I have the following: public function instructors() { return $this->...
Rainieren Rainieren
1
I am making a configurator where I want to fetch the steps (And products within that step) that correlate with the product that is clicked. I've struggled with the relations for a while because it gets confusing after a certain amount of time. But I...
cristian9509 cristian9509
16
I have this: address type is business, personal, billing, mailing, etc How am I supposed to make the many-to-many relationship? Do I need to create a new Model AddressUser and make all the necessary connections? I understand that without a new model...
ajay01 replied
Solved
anthonyhxm anthonyhxm
4
Hello, I am wondering what is the best data model to use for this case : Every user have a one and only marketplace. This marketplace can contain many products and many categories directly. But, a category can also contain other many products. I am w...
LaCoder LaCoder
4
Hello Experts, I need help for joining two tables, that will replace Query builder joins. Below is code which working perfectly fine with Joins. $invoices = SalesInvoices::where('is_invoice', 1) ->join('customers', 'customers.c...
red_devil red_devil
2
Hi, I want to design an Eloquent Relationship for this case : A User can belong to ONLY ONE Team or NONE of them but the User should persist in the database. I do not seem to understand which type of relationship would suit this scenario. I am curren...
mfoote mfoote
4
I know this is like beating a dead horse, but I still get baffled by it. It appears belongsTo is very reliant on the name of the function calling it. Case & Point... I have a table called system_logs, the table has a type id column system_log_typ...
User1980 User1980
3
Hi all, I wonder if there is a way to get a collection but have one of these specific record always at the top. ie: $names = DB::table('users') ->select('name', 'id', 'company') ->where('id', $user-&g...
redlik redlik
0
Hello, I'm struggling to create a proper eloquent query to my search box. I have a model called Topic, which belong to Category, and those belong to Subject. I've created a search livewire component on the Subject page to show all topics with the sea...
maxdiable maxdiable
6
hi, i use Oci8, and with DB::table("xxx")->get();, but the result convert my integer to string any help? br Max...
mstarkey mstarkey
8
I keep coming up agains this problem it doesn't make any sense as the data I am requesting has data and is nested in a collection, I solved it with another instance by using find(1) in the query but that was for one result with multiple relationships...
LaravelFreelancerNL LaravelFreelancerNL
1
When decoding JSON do you prefer to work with associative arrays or objects? I'm working on an eloquent driver for ArangoDB which has a JSON document model, so it supports nested JSON objects. Decoding to popo's seems to make more sense as it prevent...
777not888 777not888
2
I have: user": { "id": 1, "category_ids": [ 1, 2, 5 ] } To get "id" I use: ->whereHas('user', function (Builder $query) use ($drivers) { $query->whereIn('users.id', $drivers); but with "category_ids"...
andyandy andyandy
2
$query = User::with('actor')->where('role_id', NULL); We want filter by age (birthday is inside relationship) //this doesn't work $query->when(request()->from1 != '' && request()->to1 != '', function ($q) use ($fromAge, $toAge) {...
Create a New Discussion Button