All Questions
3,811 questions
-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
2
answers
88
views
same query different result in laravel [closed]
I want to get the rank of tag number by user.
example
code
// model
class UserItemTag extends Model
{
protected $table = 'user_item_tag';
protected $primaryKey = 'id';
protected $fillable =...
0
votes
1
answer
72
views
How to Define a money Data Type in Laravel Migrations for SQL Server?
I'm working with Laravel migrations and need to define a money column type in SQL Server. However, Laravel's schema builder does not provide a direct money type.
I’ve considered two approaches:
Using ...
2
votes
6
answers
104
views
SQL ASC and DESC ordering on same column based on another column
I want to arrange pending orders by eta in asc order and completed orders in desc order, with all completed orders appearing at the bottom of the list. Not sure if this is possible in a single query.
...
-3
votes
2
answers
113
views
How to avoid record duplication for an item? [closed]
The error, I am observing, I try to put the old value i.e already stored. However, the case is, the old value get plucked with its own id, eachtime.
SQLSTATE[23000]: Integrity constraint violation: ...
2
votes
1
answer
53
views
whereIn query return exact those ids ... or nothing
I am trying to filter something in laravel eloquent and I am not sure how to do it.
I have this array: $companyIds = [1,2,3]
The whereIn query bellow:
->where(function($query){
$query->...
0
votes
1
answer
98
views
Laravel Eloquent Order By Coalesce
I am having issues using a coalesce inside an orderby to order on 2 relationship columns. Here is the code in question:
$productList = Product::select(
'ItemName'
,'ItemCode'
,'QryGroup64'
...
1
vote
1
answer
60
views
Where is the boundary for creating a table with types in the database?
I have a model with QR codes that has a field called type. This field can have two values: 1 (Plate) or 2 (Sticker). I could simply create an enumeration of these types as an array in the model and ...
0
votes
0
answers
39
views
Why I can't query the string to date using whereRaw method throught query builder?
I have this string date which is for example "January 3, 2024'. Now I want it to compare if it greater than today's date for filtering purposes.
$query->whereRaw('STR_TO_DATE(validity, "%...
0
votes
2
answers
92
views
Laravel 7 query whereBetween 2 month
I want to find data between 2 month, for example data between months 8 and 9.
Edit: The issue is in this line
else if ($bulan1 != "semua" && $bulan2 != "semua") {
$query-...
0
votes
3
answers
62
views
How can I filter users by their full name in Laravel when concatenating columns for a search?
$dataQuery = $dataQuery->where(function ($query) use ($fullname) {
$nameParts = explode(' ', $fullname);
if (count($nameParts) === 2) {
$query->where(function ($q) use ($...
2
votes
1
answer
145
views
Alternatives to partitioning by an ENUM column in MariaDB
For performance reasons, I would like to partition a table that I have based on an enum field. This table is expected to have a very large amount of data, and partitioning on this enum column makes a ...
2
votes
2
answers
76
views
SQL/Laravel: Get parents in tree data structure
Hello everyone) I use Laravel, MariaDB.
For example, we have a table like this, let's say categories.
id
name
_lft
_rgt
parent_id
path
is_folder
1373
Windows
1
10
NULL
1373
1
1374
Glass unit
2
7
1373
...
0
votes
0
answers
55
views
Laravel 10 joinSub fromSub Expression is broken for cross database connections str_starts_with(): Argument #1 ($haystack) must be of type string
After upgrading to Laravel 10 my eloquent query using joinSub fromSub returns an error
error evaluating code: str_starts_with(): Argument #1 ($haystack) must be of type string, Illuminate\Database\...
0
votes
1
answer
21
views
laravel Eloquent ::has() QueryException on different connection
I have two databases,
db1 :
users table
db2 :
infos table
Each table I created has a Models, and I set a different connection for each one:
User.php => protected $connection = "db1";
...