hamidali hamidali
2
So i have a query where i want to select specific columns and relation count on a model. Something like this Post::withCount('comments')->select('title', 'content')->get(); Now when I use select in the query comments_count is no longer availabl...
mathiasgrimm mathiasgrimm
0
Illuminate\Database\QueryException SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "failed_jobs_uuid_unique" more details in https://github.com/laravel/framework/issues/37319...
twmcmahan twmcmahan
2
I have 2 tables: Campaigns Offers An offer can either belong to a campaign, or have a null value. Right now Campaigns has a HasMany relationship to Offers, and Offers BelongsTo a Campaign. All works, except eager loading. When I have an offer with...
grozavule grozavule
4
I have the following SQL query that I need to replicate using Eloquent: SELECT SUM(COL.ORDER_QTY) as UNITS_SOLD, SR.NAME FROM CUSTOMER_ORDER CO JOIN SALES_REP SR ON CO.SALESREP_ID = SR.ID JOIN CUST_ORDER_LINE COL ON CO.ID = COL.CUST_ORDER_ID WHERE CO...
shadrix shadrix
1
I'm trying to implement these two tables "enrollment" and "learning_progress". Look at this diagram to understand it: I'm a bit confused because of the two foreign keys. Usually, this means it's a many to many relationship. Shoul...
Proudje Proudje
2
Hello, I want to get all the id's from my json column This is is what I have for just a single id ->whereIn('a.product_id',function($query){ $query->select('product_id')->from('commen.bought_with'); })...
Proudje replied
Solved
GreatDayDan GreatDayDan
0
Where are the event recors? $events = Event::with('Memory') ->where('user_id', '=', Auth::id()) ->orderByDesc('id')->get(); Returns this: 1 101 2021-05-05 12:38:46 2021-05-05 12:38:46 1 1 ... 10 memory 103 1 10...
developre developre
6
Can we get exact updated field from the update() Thanks in advance....
GTCrais replied
Solved
vkronlein vkronlein
20
I have the following query that I can't seem to get only the latest record from. $date = Carbon::createFromDate(2021, 2, 8)->format('Y-m-d H:i:s'); $items = Model::whereDate('published_at', '<', $date) ->whereNull('removed_at') ->...
IngWARP IngWARP
1
Hi We have a customer who wants to use MsSql. The problem is that MsSql does not support 'ON UPDATE CASCADE'. We do not want to make a special version for this particular customer, so what is the best way to solve this problem. Can it be solved so th...
Laurent_awkn Laurent_awkn
0
Hey all, I am working on a mail automation app. Among my models, I have : "Training" => the equivalent of a mail campaign "Contact" => the recipients of a given mail campaign "Step" => A campaign is made of sche...
pooreal pooreal
3
This is really strange: in my User.php I have (sample scope): public static function scopeFirstUser($query) { return $query->where('id', 1); } I tried with/without static; the result is the same. When I try \App\User::firstUser()->get()...
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-&...
jdillon replied
Solved
jrdavidson jrdavidson
1
I'm working with Spatie's permissions package and trying to order my users by their role but applying a specific order of those roles by the role name. Currently with my query it its not ordering and I'm curious to know if I'm doing something wrong h...
Mqandeel Mqandeel
5
I have a pivot table between products and invoices products id col_1 col_2 invoices id col_3 col_4 product_invoice product_id invoice_id quantity amount how to returns all products in addition to the sum of pivot quantity and amount for each produ...
cosminc cosminc
2
Hello, I have an API resource that returns all the users along with a count for posts, comments and ratings for each user. I want to also include a summary in the returned array and I'm wondering which would be the best approach to do this. I was thi...
boyjarv boyjarv
3
hi, So I have Users table and in the user model, I added: public function favorites() { return $this->belongsToMany(Artwork::class, 'favorites', 'created_id', 'id')->withTimeStamps(); } I have a favourites table and an artworks...
Is anyone else experienced a change with booleans in Laravel 8 on Postgresql 13.2? I have a migration that has been working for years which has suddenly stopped working. I find that the only way I can set booleans is to use a string, ie<value>...
GM replied
Solved
garrettmassey garrettmassey
5
Hello! I have a database that has several tables, but we only need to focus on 3: providers id name status type_of_care_id caretype id name category category id name A provider can have 1 care type, and multiple care types can belong to 1 categ...
kramsuiluj kramsuiluj
2
I have a Product and Size Model with a relationship of many to many, I want to get a product's specific size, each of the product has 3 sizes, How do I get a single size of a product?...
kramsuiluj kramsuiluj
3
I have a Product and Size table with a many to many relationship, on the pivot table I added another column named Price. How do I access the Price column on the pivot table?...
ChrisF79 ChrisF79
2
I have a migration where I'm trying to add a foreign key. The code I have is: public function up() { Schema::table('contract_details', function (Blueprint $table) { $table->foreign('contract')->references('id')->o...
Spyralex Spyralex
0
I have three models Product, Variant and Option. class Product { public $id; public function variants(): HasMany { return $this->hasMany(Variant::class); } } class Variant { public $id; public $product_id; public func...
apolope apolope
6
I have 2 models, with many to many relationships. Books have many lenders Lender have many Books Tables in the database -> lenders -> books -> lend_book I need to check which books are not on lenders. On Lend Model public function books()...
davepgreene davepgreene
7
Hi. Is there a way to retrieve all of a model's relationships short of parsing columns in every table to see if _id exists? Ideally I'd like an array with the model name (with namespace) and the type of relationship. Possible?...
anon_ replied
Solved
davestewart davestewart
14
Something like $model->listRelated()? I assume not as relations are encapsulated inside methods. My second assumption is that this means I simply need to create a mechanism to get this information elsewhere, perhaps a model property, method, or ot...
anon_ replied
Solved
Stengi Stengi
1
Hello dear Laracasters 👋🏻, if the title wasn't confusing enough for you already, let me explain my situation to you. I am currently facing a tricky problem that I can not solve. The following scenario causes me the problems: A user can create o...
Stengi replied
Solved
georgewashington georgewashington
2
Hello! In Blade, I need to display the rooms and the names of user who own the rooms + pagination. The rooms are displayed very well, but I do not know how to display related name of user near. i. imgur. com/mOVGuJk. png...
EvilAlex EvilAlex
7
Hi all! I have a little problem with new factories. My models has custom namespaces like App\Domain\Product\Models\Product. And i want use a simple factory namespaces like \Database\Factories\ProductFactory. When i try to make them from seed class: P...
loose1eaf loose1eaf
3
I want to refactor my source code when filtering records in all and specific fields. Currently, I'm filtering all fields by passing 'search' in my request: GET request: /api/users?search= public function index(Request $request) { $search = reques...
Jakub003 Jakub003
5
This is probably a huge newb question, but I can't seem to find any tutorials or examples for how to write out the livewire public function to make the group thing work. Any links to a guide would be much appreciated as well :) In this documentation...
BrainyT BrainyT
4
Controller or Model which is best to put eloquent queries?...
joshblevins joshblevins
1
Is it even possible to count this using eloquent. Table 1 (competency) Table 2 (Required User Level) Table 3 (Users) Relates to tb 2 one to many | Relates to tb 3 one to many I am trying to get a count of h...
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
Create a New Discussion Button