schwartzmj schwartzmj
1

hasOneThrough where two models are the same table

Here's a brief summary of my models that I want to connect through a hasOneThrough relationship: User with $user->role === 'agency' and $...
kitten kitten
20

Retrieve posts from categories except one

Hello! I'm at my wits end all I have left is pulling my hair :( My setup is as following: I have Posts & Categories as a many to many relationship...
kitten replied
Solved
Eloquent
20
149
marcorieser marcorieser
6

MorphTo with specific methods

Hi I have a User model which morphs to Employee and Guardian (like parent). protected function role() { return $this->morphTo(); }...

Query data from through pivot table based on slug

Hi Everyone, I have a route setup that uses /books/category/{slug} to get books based off a slug but I'm having an issue getting the data to return quic...

Best practice: firstOrCreate on high load system

Hello everybody! We currently have an interesting problem on a system with higher access rates: We are providing an Api Call, which outputs information with appropri...
MUM replied
Solved
Mushr00m Mushr00m
16

Eloquent : Count of posts for a period with one row per day

Hi, I need to create a graph for the last 30 days, so I need the count of post created per day. Right now I'm having this : $chartDatas = Post::sele...
Eloquent
16
3937

return last record by forign_key

i have chapters table, student take exams , in student_exams i store ('id','chapter_id','mark','user_id') I want to list all chapters and marks of last taken...
shineraj shineraj
9

Compare sum of relational column

Hi, Can i compare sum of the relationship column with my parent table column without using joins ?...
theUnforgiven theUnforgiven
11

Eloquent when condition question...

Hi all, I have the following code which seemed to work for the type but when I add more for postcode, bedrooms etc it doesn't then work....
Ev-genius Ev-genius
5

Linking table

Hello! Need to design a database for the training service. I made tables: Categories, exercises, programs and one linking table programs_exercises:...
Romain Romain
2

onDelete('cascade') means...

hey very quick and easy one but I'm confused with the docs. When I write: $table->foreignId('submitted_by')->references('id')->on('users')->...
jesse_orange_newable jesse_orange_newable
0

Using Laravel Scout or an SQL LIKE operator

In one of my projects we have Articles and Events (singular) and I wanted the ability to search through them with a search bar. Laravel Sco...
phoenixg phoenixg
1

How do I upgrade illuminate/database from v4 to v8(currently latest) ?

I use illuminate independently (without laravel), I have many eloquent models, how do I upgrade them from v4 to v8, because v4 does not support highest version of PHP, so I...

Doest $table->spatialIndex('location'); support PostgreSQL ?

I need to implement this spartial GIST index for Postgist CREATE TABLE test (geog GEOGRAPHY(POINT)); CREATE INDEX gix_test_geog ON test...
Drivez Drivez
4

Get BelongsTo with trashed

i found an old article that says in a belongsTo you can ask for tht soft deleted recordes as well, like. this: return $this->belongsTo(Income::class, 'incom...
andyandy andyandy
3

Eloquent modify DB data before comparing them with where()

I want to make sure that text is not duplicate. Something like: $record = Record::where('text', request('text'))-> But I want to strtolow...
andyandy replied
Solved
saurav77 saurav77
3

How to build query for google bar chart in laravel?

My Database looks like this id | country_name | population | created_at 1 | USA | 2000000000 | 2020-02-04 2 | China | 2200000000 | 2020-...
locopetey locopetey
10

Append new attribute based on relationships

Hi, For brevity, i have three tables with the following columns: Categories -id -name -slug Topics -id -name -slug -category_id Subtopics -id -n...
protarr protarr
3

Using Laravel's eloquent models, how do I get a plain left join result?

I want to avoid accessing the tables directly using the DB class. Let's supose I have these 2 related tables. user id name age email id u...
protarr protarr
3

Traverse models in multiple levels using Laravel's eloquent

I am using Laravel 8. Suppose we have 3 tables. table_a, table_b and table_c. A simple 3 levels of tables. Table A has...
guyinpv guyinpv
6

hasOneThrough confusion

Simplified three tables: User (id, name, car_id) Car (id, name, maker_id) Maker (id, name) On the Maker model, I used a hasManyThrough to grab all the users with tha...

updateOrCreate tries to update non existing column

Hi, I recent been through the 'Laravel from Scratch' series and starting building a website as practice, it is basically a housebuilder type website. I added a feature wher...

Many to Many contains

Hi, I have a relation many to many and need to know through the emission id if in the file table (many to many) the word "wait" exists in status from table files....
fabuy replied
Solved
MartinZeltin MartinZeltin
4

How to create a static and non-static method on Model?

I would like to create a new method on my model where I could call it in 2 ways class UsersController extends Controller { public function index() {...
BartHuis BartHuis
13

make an empty relation

hi, i would like to make an empty relation, is that possible? tried class Testmodel extends Model { /** * Get the testrelation records associ...
Eloquent
13
2830
twopiers twopiers
12

Eloquent save converting unicode characters

I have an app that pulls some information from an API and simply saves it (via an Eloquent model) to MySQL. I'm running into an issue when a string from the API contains an...
Eloquent
12
134
ExpDev07 ExpDev07
1

Accessing model properties in scope

Hey, I wish to scope posts of users that have not blocked each other, for this I try the following model: class Post extends Model {...
edgreenberg edgreenberg
4

Need to get attribute without going through accessor

I'm writing unit tests for my mutators and accessors in a particular model. I set the value in the mutator with: public function setParkingTypeAtt...
Eloquent
4
2351

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

Hi! I'm currently working on a accounting software, and I'm facing a problem with the Laravel 8 Paginator. This is the error I'm getting Method Illumi...
Foks replied
Solved
boyjarv boyjarv
0

Group By created_by date - error in SQL syntax

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax here is my SQL: Tagin::latest(DB::raw("DATE_FORMAT(c...
alamin899 alamin899
7

Convert SQL to Elequent

how can i convert to elequent select pay_sch.student_id, pay_sch.payment_head_class_id, pay_sch.ps_id, SUM(pay_sch.amount) total_payment_schedule_amount, SUM(pd.paya...
EvilAlex EvilAlex
5

Factory for model with custom namespace in Laravel 8

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 na...
SpuriouslyAwake SpuriouslyAwake
11

Pluck from a nested collection?

Hi, I'm trying to pluck the strand_id value from the following collection Illuminate\Database\Eloquent\Collection {#3820 all: [ App...
Eloquent
11
7869
webfuelcode webfuelcode
1

Eloquent where() for two column match

Trying to create a search result for posts that will search on the title and description column. I can make it happen like this for one: public functi...

How to access data through the pivot table

Hello, I have a many to many relationship and naturally a pivot table. Here is my Project model: public function dev_names() { return $this->be...
Create a New Discussion Button