All Questions
24,029 questions
2
votes
0
answers
44
views
Schema::hasColumn() returns false for existing SQL table columns using Laravel and external database connection
I'm working on a Laravel 12 project that connects to a Microsoft Dynamics CRM SQL Server database through a custom connection. I've run into a puzzling issue: Laravel's Schema::hasColumn() returns ...
-1
votes
1
answer
36
views
Database question about simple Categories & Subcategories. Laravel 11
I want to have Categories with related Subcategories, It must looks like this:
Category: Broth
Subcategory: Chicken broth, Meat broth, Vegetable broth
And I'll create create_categories_table & ...
1
vote
1
answer
66
views
Laravel N+1 when accessing a pivot relationship and the related model (unit)
I got n+1 query while working with my models and pivot
Recipe.php:
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function ingredients():...
0
votes
0
answers
44
views
Unable to call the faqs in proper sequence in laravel, succeded in fetching data but not in that way which i wanted
What I'm trying to build
I'm working on an FAQ system. At the top level, there's FaqType, which represents the type or category of FAQs.
Each FaqType can have one or more FaqSubtypes, and under each ...
-4
votes
2
answers
105
views
Convert this Eloquent model function to a MySQL query? [closed]
I need to convert this Eloquent Model Function to a MySQL Query:
public function currentPrice(): HasOne
{
return $this->hasOne(Price::class)->ofMany([
'published_at' =>...
0
votes
1
answer
56
views
How to update a Laravel Eloquent data, calculating a date diff
I have this problem.
I need to update all data from a Table, each time incoming batch finishes inserting.
What I have to do is:
Incoming data has CreationDate, so I need to do a DIFF with current date,...
1
vote
0
answers
99
views
How to Eager Load Aggregated Fixtures from Original and Duplicated Competitions in Laravel?
I'm working with a database design where competitions can be duplicated, and I need to efficiently query original competitions along with aggregated fixtures from both the original and duplicated ...
1
vote
1
answer
74
views
Is it possible to setup a permanent property on a Laravel Eloquent model using withCount()?
I have a Laravel Eloquent model called Team that has a hasMany relationship to users. Is it possible to easily setup a user_count property that is permanently on a Team model? or do I always need to ...
0
votes
1
answer
62
views
Aggregate for custom attribute
My tables are: projects -> tasks -> commands
Trying to calculate average on field duration
Project::with('tasks.commands')->withAvg('commands', 'duration')
It can't work because Eloquent ...
2
votes
1
answer
34
views
Laravel Eloquent: aggregate for table
My tables (and Laravel models relations):
projects -> tasks -> commands
Calculate count of tasks:
$body = Project->withCount('tasks')->get();
Fine.
Then I want to calculate count of ...
0
votes
1
answer
28
views
Image tag not rendering on Gmail but will render on Outlook
Using laravel, I have a method in my controller that is taking the base path of a .png file and base64 encoding it before sending it to my blade template. The image is able to be rendered on outlook ...
1
vote
1
answer
48
views
How to find model with condition on multiple relationship?
I have the following model with two one-to-many relationship:
class Dad extends Model
{
public function sons()
{
return $this->hasMany('App\Models\Son', 'dad_id');
}
public ...
0
votes
0
answers
37
views
How can be used TagsInput component to store related data using model hasmany relationship?
I have eloquent model to store specific car brand model years:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class CarModel ...
-2
votes
2
answers
92
views
Eloquent query returning null when using a variable
I am having a issue where when i write out a eloquent query using a variable it is returning NULL but if i write out that variable value in text it returns data.
This is my code
$code = 'Test123';
...
1
vote
2
answers
108
views
How to update and delete records in a table based on a new request?
I need to update records for Guide Steps (Every recipe has steps/instruction and my table was created for storing this data)
I was able to create those records in the db with quite easy syntax:
...