mike_hasarms mike_hasarms
5

Select children of active parent models (deleted_at = NULL)

I have a 1:M (hasMany/belongsTo) relationship between two models. The parent model might have been soft deleted, and I want queries of child models to exclude result...
PJijin PJijin
2

How to convert this sql query to Eloquent ORM.

SQL Query SELECT v.product_id FROM ( SELECT product_id, count(*) AS matches FROM product where filter_id IN (2,4) GROUP BY product_id...
PJijin PJijin
11

Eloquent query to filter same column values

Hey I want to get the product_id from this table Table product_filter I want to get the product_id...
Eloquent
11
158
cmdobueno cmdobueno
18

Observer "not observing"

So, I have a model: JobsiteCostTemplate namespace App\Models\JobsiteCost\JobsiteCostTemplate; use App\Models\BaseModel; use App\Models\JobsiteCost\JobsiteCo...
skinnyvin skinnyvin
24

$this is null inside model

I am in a tangle with counts and relations and noticed that $this is null on methods within the Store model. I am only interested in Visits belonging to the...
Eloquent
24
126
kennyhorna kennyhorna
2

How to use find in set in laravel query?

Is there any way we can set it in model if possible please guide User id name b_id 1 Alax 1,3 2 Rex 2,4 3 Lex 2,3 Books id...
princeoo7 princeoo7
4

Eloquent with, withCount gives 12 as total records but the function with groupby on date gives 9

I have 3 tables, Users, Tasks, TasksSession. what I am trying to find is total session conducted and total days the user was involved in that task based on cre...
mohammadbasir mohammadbasir
2

MySql query to Laravel Eloquent conversion.

Helo I want to convert this query to laravel eloquent. Any suggestion how to do that? SELECT * FROM chat WHERE (id_participant1 = 1 OR id_participan...
chabwino chabwino
2

Eloquent find hashed

Hi I have a database table with two fields for a name ('name', 'name_h'). 'name' contains encrypt('Bob') 'name_h' I want to be searchable so I use Hash::make('Bob')...
AliRezaBeitari AliRezaBeitari
3

Laravel Passport multiple guards

Hi! I have multiple authenticatable models (User, Admin, Member). I wanted to use Laravel Passport as my API authentication system, b...
abingpj abingpj
2

How to use Substr in Laravel query?

Hi, I want to use substr in laravel query, but I am getting error. Here's what I have tried so far- $items2 = Course::where('schoo...
thebigk thebigk
4

Eloquent User Provider Causing Duplicate Query

I'm required to calculate the current 'rating' of a user (model) based on a relationship with Activity(model). I therefore have the following in m...
abingpj abingpj
1

Laravel raw query to Eloquent.

Hi, I have a query that I want to convert it into eloquent. \DB::select('select * FROM brands WHERE id in ( select brand_id from products WHERE catego...
tealiedie tealiedie
3

How to change primary key of related model in belongsToMany relationship ?

guys. how can i set related model primary key in my belongsToMany relationship ?.. public function directories() // here i need to change Provider's primary...
shrooq shrooq
1

How to add an attribute in my relation?

I want to add an attribute in my relation and return it in my API but I should use request in my model. Book.php protected $appends = ['userState']; p...
shantodev shantodev
2

Why Collection::save does not exist?

Hi, Suddenly I am getting this error. Collection::save does not exist. Here is my code- public function register(Request $request) {...
Bozboz Bozboz
4

Eloquent's morphedByMany method

As far as I can tell, unlike with one-to-many polymorphic relations using morphMany/morphTo, there is no way to retrieve all of a polymorphic relation when using m...

(Polymorphic) Many-to-many relation to multiple models

Looking for a simple way of doing the following in Laravel 5. Imagine these models and interface Competition User Team Partic...
Stucks Stucks
2

Avoiding duplicates in a Many to Many relationship with the same table

I have a kids table and a kids_siblings table to link kids that are related to one another, so it references the same table. I have this semi-working by defining the...
princeoo7 princeoo7
3

Belongs to many Count based on created_at and task_id in laravel

I have 2 tables User and Task. I am connecting then with belongsToMany relationship. At the moment I can user $user->...
FallOutBoi FallOutBoi
5

Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

Hey guys, i am trying to run this simple query but its throwing Method Illuminate\Database\Eloquent\Collection::paginate does not exist. error. My code...
connecteev connecteev
1

MySQL Trigger to keep num_comments (across a nested comment tree) up-to-date when a comment is inserted / deleted

I have a nested structure of comments. A comment can be made on either a post, or on some other comment (or sub-comment). Therefore, the possible values for comments...

WhereHas performance issue in a big database

Hi guys, I have a significant performance issue in a simple scope. The scope uses WhereHas for a table that contains 80k records. Let's imagine a forum has 1.000 use...
illmatic illmatic
6

Easiest way to query based on a relationship

I have a Role Model that has names such as "admin". Each User has a number of roles public function roles() { return $this->belongsToMany('A...
gummiforweb gummiforweb
5

Laravel v5.3 - How to disable eager loading on polymorph relationship?

Hi, I'm wondering how can i disable the eager loading when I'm retrieving the polymorph relationship? Here's my current setup (strip-down version). Post Model...
codetycon codetycon
3

How to make relation between 3 tables in laravel using laravel relation?

I have three tables: SET NAMES utf8; SET time_zone = '+00:00'; DROP TABLE IF EXISTS `api_credentials`; CREATE TABLE `api_credentials` ( `id` bigint(20) un...
Hujjat Hujjat
13

How to relate Student with Class and Eloquent relationship

Hi, I get this error while try to show student's class in view. ''' Call to undefined method Illuminate\Database\Query\Builder::belognsToMany() (View:...
Eloquent
13
303
CodebyRay CodebyRay
2

groupBy not working in closure.

Hello, I have searched and have not found an answer to this problem I am having. I have either looked at this too long and just cannot figure it out or it's so simpl...
thebigk thebigk
7

Calculating permalink for each reply, without N+1 problem

I've two models: "Post" and "Reply". The relationships are defined on following models as follows - Post: public function replies()...
Youtaka Youtaka
1

Laravel - Recursive relationships without some data

Hi everyone, I'm working with 3 Models which are Panel, Item and PanelContent. PanelContent has 3 properties : parent_id (who is a Panel)...
avictory avictory
7

Laravel cache bug? Or I do something wrong?

Hello, This query with ->first() was used before I call ->delete() and I guess Laravel saved the result in cache, but after I call ->delete() it seemed calling -&g...
cyberEst1919 cyberEst1919
10

Can't get Lazy Collections to work

Hey there! I'm having troubles getting the new Lazy Collections to work. I'm not working in Laravel, but using the Laravel Container and Database components as compo...
Eloquent
10
101
thebigk thebigk
1

How do I merge two collections with conditions?

I've two collections: $gains : [ { "gain": "40", "user_id": 2 }, { "gain": "10", "user_id": 1 }...
afoysal afoysal
10

Use find() and with() together in Laravel query

I have 2 tables employees and employee_locations. One employee has many locations. I need to find out one employee record with related latest...
pedroroccon pedroroccon
3

Disable global query scope on specific controller

Greetings, I created a global query scope in one of my models. The scope is called "waiting", and it is used to indicate that a follow resource is waiting...
Create a New Discussion Button