MuhammadYasser MuhammadYasser
3

all() vs get() - Laravel Eloquent

which better between these lines? and why? $activeCustomers = Customer::all()->where('active', 1);...
arctushar arctushar
7

sql query too slow

I have sql table with 2,685,222 rows and have below columns id, codelist_id, ltp, trade, value, volume, date, time, created_at, updated_at. Now When I search...
captbrogers captbrogers
5

Deep Replication (Model + relations)

I'm trying to replicate a model, but I also want to replicate each of the relationships it has from an array that I have. Using the...

Elegant way to fix duplicated many to many relationships

Hi everyone I'm looking for some elegant way to correct an issue I created. I have a Roles table which is a Many-to-many relationship with Users. Due to a bug in my code I...
ayekoto ayekoto
7

Nested relation with condition ?

I know I can do this User::with(['scores.class'])->where ('id', 2)->get(); But Was wondering if I can do this User::wit...
Rymercyble Rymercyble
10

get everything from table with every related data from many to many relations

Hello, I would like to get every user with every language they know I have got tables users, languages, and known_language_user in user model defined relation...
Eloquent
10
191
lbchristina lbchristina
2

Add Parentheses multiple where , orwhere

how can I add parentheses to a query please check the below query : $results=$query->where(function($query) use($fn,$mn,$ln){ $query->where('FirstName','like',...

Save one to many relation with dynamically added fileds

Hello! I have two models: Phone and Person, person has many phones. <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Phone exte...
RadicalActivity RadicalActivity
2

Confused with Laravel's hasOne Eloquent Relationships

I have a new Laravel 5.8 application. I started playing with the Eloquent ORM and its relationships. There is a problem right away that I encountered. I have...
OptimaDesign OptimaDesign
1

Update hasMany Relation

Hi, I have a user that can have many Presidents. Within my edit method, I'm trying to update a president with a new date_from/date_to. How can I only update one entr...
mostafalaravel mostafalaravel
2

Seed Factory

Hello , I have this error when I run php artisan db:seed BadMethodCallException : Call to undefined method Illuminate\Database\Eloquent\Relations...

Is it possible to reference multiple tables?

I want the user_id to grab all the id from 'admin', 'customer', and other user tables.. Can it be done with something like this?...
adibhanna adibhanna
17

NeoEloquent - Laravel ORM for neo4j (GraphDB)

check this out guys! a great ORM for working with Graph DB, specifically Neo4J. you can use almost the exact syntax as Laravel's Eloquent....
Eloquent
17
1643
roerjo roerjo
1

Soft delete on specific date

Anybody know of a way to have a model soft deleted on a passed in date rather than the current date/time? I want to call a soft delete which will trigger the deleted model...
khanvuthy khanvuthy
14

mb_strpos() expects parameter 1 to be string, object given

Dear all, I have one problem with my code and I am can't figure out what I was wrong, Here is my code $jobs_obj=Job::with(['skills',function ($sk...
Eloquent
14
3907
mostafalaravel mostafalaravel
3

Seed Factory and pivot table

I have two models : Group Model <?php namespace App; use Illuminate\Database\Eloquent\Model; class Group extends Model { public function users()...

How eloquent relations work

I know that when you create a model using php artisan make:model Modelname -m it will pluralize the model name when it creates the migration. But when the name ends in &quo...
fabricecw fabricecw
3

Complex query performance

Hey! I need to track statuses on an order model. It's a many to many relationship between order and status, since an order has multiple statuses and a status is used...

Birthday list

Hello, I have data with many people. I need a birthday list for the next two month. Which would be the laravel way to do that? Raw SQL or are there other options?...
Bvanhaastrecht Bvanhaastrecht
2

Trying to get property of non-object with relation

Hello, I'm pulling my hair over here. I'm trying to access an relation, but it's telling me there isn't one. While when I convert it to json, it's defenetely there....
oliverjkb oliverjkb
4

oneToMany relationship with history

Hi there, I am struggling a bit with a new feature I'd like to implement. I have a Model Server that holds information about bare metal machines...
DavidPetrov DavidPetrov
2

Select sum of realtion's attributes in query

I really can't figure it out although it's fairly simple... I've got two tables: orders and revenues and I want to add a global scope to my...
jaheller jaheller
2

sortBy with() statement

Is there some way I can use a statement like: $conversation->with([ 'messages.sender' => function ($query) { $query->orderBy...
Reached Reached
4

Returning a single record instead of collection

Hi guys, I am building an API where I have 3 different models: Campaign Contract User A Campaign can have many different Contract...
joshblevins joshblevins
1

Elequent Query Help

I have a table of Employees whom take classes with the following relationships Courses Have Many Classes Classes Have Many Completions Completions Have...
hirokku hirokku
4

how to order entries by likes of user_id?

Hello I'm almost all day on this. I'm working on some laravel app and I have a table called "entries", I save in this table recommendations of name for a contest....
FallOutBoi FallOutBoi
4

Weird function on null error

I am trying to insert inside a table when user has selected a subcategory but when its empty it says "Call to a member function first() on null" Even...
oleshkin oleshkin
1

How to structure a table(s)?

Seeking for experienced advice on structurizing the database table. I have a 7 day money balance table for each user, where the balances are calculated on-the-fly, but the...
Sultenhest Sultenhest
6

Querying a hasMany through a belongsToMany

Hi guys I'm currently practicing my Laravel skills by building a Twitter clone and i'm still relatively new at building eloquent queries. I'm stuck building t...
popouerk popouerk
3

Chaining relationship

Hello, I tried to find a solution for my problem but i couldn't since i'm not even capable to formulate it properly. By default i named it "Chaining relationship"...
hunterhawley hunterhawley
2

Access relationship from inside a where clause (or however I'm supposed to do this)

Hey y'all! Quick question this morning. I've got two tables: 'stats' and 'stat_metas'. 'stat_metas' holds all the 'meta' information about a stat, like its name, descriptio...
DavidSprauel DavidSprauel
1

DB::raw adds `` weirdly to my request

Hi guys, I got a request with a custom select which works with a condition return DB::raw(' CASE WHEN topics.type = '...
ExpDev07 ExpDev07
11

Eloquent HasMany whereIn

Hey! I have a user model with an array of identifiers. An identifier can be either an IP address or something else. However, users can be banned. And this is done through t...
Eloquent
11
222
daniel21gt daniel21gt
3

Problem with translation of query to eloquent, laravel 5.5

What a companion. I have tried to convert this sql query to eloquen, but I have messed it up when joining another query. select usuario_ad, count(usuario_ad)...
Create a New Discussion Button