durairaj durairaj
11

How to get data from multiple table interrelated with each other

user- table id name email status 1 durai [email protected] active orders -table id user_id order_no total 10 1 #74749 250 order_items - table id o...
Eloquent
11
288
coder72 coder72
5

How to make users column empty from SQL Statement ?

Like yesterday, This is my users table and i want to make coursable_id and coursable_type empty ? id | name | email | coursable_id | coureable...
t0berius t0berius
4

laravel insert relations based on two models

Using the following model Product: public function favouriteUsers() { return $this->belongsToMany('App\User', 'favourite_products'); }...
Mqandeel Mqandeel
2

get first 10 tags

$blog= Blog::where('slug',$fslug)->with('tags)->firstOrFail(); this will return the spacific blog with all related tags how to return just...
devondahon devondahon
2

How to use multiple oWhereRaw clause with an array of search terms ?

How to have multiple orWhereRaw clause, one for each element of my array: $array = ['foo', 'bar', 'hello', 'world']; re...
coder72 coder72
4

How to delete users from SQL Statement

My users database look like this I want to cleany database data so i am cleaning from localhost. id | name | email | coursable_id | coureable_...
coder72 replied
Solved
devondahon devondahon
5

orWhere with array of search values and wildcard

I have an array of search values set like this: $string = 'foo bar hello world'; $array = explode(' ', $string); $array = array_map(fn ($value) => '%' . $...
InToSSH InToSSH
6

Teams-Members-Users - help with DB structure

Hello, I am building an app for teams and their members and I am ripping my hair out trying to figure out the structure to be best and simplest to use with Eloquent. Also I...
webfuelcode webfuelcode
0

Using cviebrock sluggable with validator

I am using cviebrock/eloquent-sluggable slug package for my project and want to use it with validating data. Tell me how to use it... Where and how to u...

query on created_at with carbon

I have this query Community::where('created_at', Carbon::now()->subDays(3)->toDateString()) and in db i have this raw "...
Snapey replied
Solved

get 50% percent of gender

i have user table with gender i need to pick up 20 users half of them female i did that private function getUser() { $female_users...
mkshingrakhiya mkshingrakhiya
4

Query performance degraded after converting raw queries to Eloquent ones, How do I speed it up?

I had loads of raw SQL queries on a single page, 110 to be exact. It took nearly 1.2s to get data from all of them. Now, I managed to combine them all and got all the neede...

Multiple Paginations on one page

Hi! I'm currently looking for a way to have multiple paginations on a single page, with they are interfering with each other. How can I do that? Best Regards, Foks...
Foks replied
Solved
Eloquent
11
236
msslgomez msslgomez
6

WhereHas returns unexpected item

I'm trying to get all products for a store where the inventory is greater than 0, but it's returning a product that has -1 inventory for some reason. $produc...
Gavmrz Gavmrz
1

WhereHas relationship latest()

I have a model Job with relationship lastAction. public function lastAction() { return $this->hasOne(\App\Task::cl...
bljdavidson bljdavidson
7

Updating Column to allow nullable but can't because of type enum

Hi all, I am trying to update a field on my table to allow it to be nullable. public function up() { Schema::table('videos',...
phpguru phpguru
2

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

I've been using Docker for Windows with Laravel 5.3 + Spark for nearly a year. Now all of a sudden, something has changed in my environment and I cannot figure out what. Wh...
Eloquent
2
3064
devondahon devondahon
1

Get subarray as an object

This request: Animal::all()->groupBy('designation') returns this result: { "dog": [ { "id": 1, "ra...
siyaniz siyaniz
16

Finding the current questionnaire_id.

I'm making a questionnaire for guest to do on my website. I have a questionnaire model and it has a hasMany relationship with my SurveyResponse model. After the user...
siyaniz replied
Solved
Eloquent
16
187
staticcode staticcode
8

firstOrCreate not working properly

Hi guys, I recently made an import script by using Laravel's firstOrCreate function which, to my understanding, should update if non-existant and other create the gi...
Eloquent
8
1065

Eloquent where optional fields equal something

Hi, I'm not sure how to handle this query. Hope one of you might be able to help me. Got two tables: "settings" and "items". I need...
MB replied
Solved
al_imran_ahmed al_imran_ahmed
4

What is the way of adding executable eloquent query scope

In Laravel Eloquent, we can do something like: User::active()->where('reference', $request->ref)->first() Here active() is a scope and w...
uniqueginun uniqueginun
3

Laravel group by clause

I have a very hard situation and I been trying to find a solution either with query builder or eloquent but had no luck for days. I have a database table/eloquent mo...
andersb andersb
15

Casting variable amount of fields to json

I am currently trying to figure out the best way to use Eloquent casting when dealing with a variable amount of fields. Say I have a model options which...
Eloquent
15
178
datarecall datarecall
1

Help With New Structure Ideas

I am looking at re-designing my database structure for part of this site I am working on and would love your input. I currently have a Diary and a Diary can have man...
princeoo7 princeoo7
4

Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::stocks() error

I am getting Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::stocks() error. What is wrong with my logic ? below code is workin...

How to call many to many relationship while converting the blade to pdf

Hi, I'm translating a Event Report view to pdf. I retrieve the data from a table called 'event_reports' from database but some columns are many to many so they are n...
princeoo7 princeoo7
10

How to filter Data to be displayed in an api call

Below is my api output at the moment. 0 id 1 title "Enim illo aut." slug "enim-illo-aut." created_at "2020-10-12T10:55:34.000000Z&...
Eloquent
10
174
addorange addorange
4

Can I group by a json property?

Hi there, me again ;-). Can I make an eloquent query to group by a json column property like: Model::get()->groupBy('column->property')...
Eloquent
4
1375

How to get data with specific id

Hi, I want to get the data with specific id but I have also some relationships. How can I write the query? Here is my controller: function get_...
Eloquent
12
115

How to get selected day name in date picker?

Hi, I want to display the day name of the selected date. Now, I can choose date via date picker like this: 13.10.2020 in my panel but I want to display like this: 13...
andraszoltan andraszoltan
2

Handle multiple Eloquent Model DB connections in jobs - based on the settings stored in database

I have two kind of models in my multi tenant Laravel 7/mysql application, ex: Company -> uses the default connection/central db, configured th...
DEK338 DEK338
4

Return empty results on groupBy month

Im trying to return results by month / dealership / department, which works great, the only problem Im facing is that for any null values found, it doesnt include the month...
DEK338 replied
Solved
alnouirah alnouirah
3

Retrieve user circulars without duplication

Hello all :) . I have a user model which belongs to many categories and the category model belongs to many circulars . so , my question is how to retrieve the circulars of...
msslgomez msslgomez
5

Sum on relationship (Product / Inventory)

I'm trying to display the products and the stock available in inventory. These are my models //Product public function inventory() { return $th...
Create a New Discussion Button