Cannot add foreign key constraint - but why?

Hello everybody, I got this table schema: public function up() { Schema::create('cars', function (Blueprint $table) { $table-&...
Eloquent
2
1071
dylanryan dylanryan
10

Query gets extremely slow

private function getArticles() { $query = Article::orderBy($this->sort, $this->sortOrder); if ($this->searchTe...
Eloquent
10
1142
mostafalaravel mostafalaravel
10

model update: how to check if there is changes ?

Hello I would like to know if there is a way to check the data in model update before saving, For example in my controller I want to save() only if there is s...
Eloquent
10
1139
AnnBooney AnnBooney
2

MySql to Eloquent

How would I convert the above MySQL raw query to Eloquent query? "Select codigo, referenciacliente, nombre, nombrecliente, diasaviso from articulos where (artic...
Prabodhana Prabodhana
3

Get Foreign key details

i have two table university table and program table.. In program table has foreign key 'universityID'.. I add the relationship between this to in program model has "b...
Eloquent
3
1091
Aronaman Aronaman
11

Assign relationship for specifi user role

I have refund tables 1 to Many relation with user admin role. I have users table the question is how to assign for specif role in the model I try this ... //u...
Eloquent
11
999
MartinZeltin MartinZeltin
2

How to get Posts with Comments AND Replies?

So I have 3 tables - Posts, Comments, Replies. I would like to get All Posts with their comments and with the replies of comments. Like this Posts: [...
ChrisSFR ChrisSFR
10

Enable Json1 Extension for sqlite3

The docs says, that we need to use the json1 extension for sqlite3 if we are using json where clauses in our application....
Eloquent
10
766
afitriali afitriali
1

whereColumn in whereHas not working for equal value

I have a Document model which hasMany DocumentVersions. I'm trying to add a status filter for my model. There's no status column so I use whereColumn condition inside the w...

Return pivot-data depending on the context of the model (loaded as relation or not?)

Hello, I'm just thinking about whether it's possible to influence a model to return values depending on which pivot table is loaded. The Model I am referring...
AwadGorg AwadGorg
2

Getting Call to a member function with() on string when getting data from db

Hello, I have this basic eloquent DB select code but It shows me an error when i try to send this data to a view with both ->with or ->compact this is the code am usi...
princeoo7 princeoo7
12

where clause on eloquent relation returns data even on false condition

in my model, below is the code public function children() { return $this->hasMany(Category::class, 'parent_id')->where('is_pa...
Eloquent
12
581
dad007 dad007
2

tell me how a similar request on Eloquent will look

tell me how a similar request on Eloquent will look SELECT prices.id ,price, links_id, products_id, markets_id, link FROM prices Left JOIN links ON links.id = links...
danimohamadnejad danimohamadnejad
1

withSum on a column similar to withCount!

hello please consider following tables: products==>> id name, reviews==>id score productId I want to get a list of proudcts along with total number of re...
Eloquent
1
1077
nekooee nekooee
2

how to define a convenient shortcut for accessing distant relations, between “OneToMany” and “manyToMany polymorphic”?

I have three models: "Article", "ArticleTranslation", Tag". Article translations in different languages are stored in the ArticleTranslation...
borrie borrie
0

Query taking long

This problem is solved!...
ahmadbadpey ahmadbadpey
5

first() and take() do not work correctly in Eager Load laravel

I have a Post Model that have a hasMany relation to post_pics and belongsToMany relation to Category Model. I want to fetch All Posts and All their Categories but Fi...
pHaider pHaider
2

How to perform this scenario?

Hi brothers, I'm a newbie with Laravel and need help with this scenario, I have a Building which has many Floors and each Floor has many Spaces. My question i...
AwadGorg AwadGorg
3

Select and groupBy are not working

I don't know how to explain this so just let me show you I have this code $top_games = Browsergames::join('browsergames_rating', 'browsergames.id', 'browserg...
jim1506 jim1506
10

Count in a joined table with DB

I have some code to get data for a datatable $pr = DB::table('properties') ->leftJoin('photos', 'properties.id', '=', 'photos.property_id') ->select(['properti...
AwadGorg AwadGorg
4

Help selecting data from the database using laravel

Hello, I have this gaming website and on the website, I have a form that enables users from reviewing the game and am allowing guests and members to review the games now am...
Aronaman Aronaman
5

Eloquent and tables

3 tables Cash_payment, local_payment, online_payment. I have daily total price calculated for each table. .my question is its possible to sum total price of 3 tables...
AwadGorg AwadGorg
2

Finding rows in database table using laravel Eloquent

Hello, I Have this code $checkRatings = $ratingTable::select('browsergames_rating.id')->where([['user_id', $userId], ['game_id', $gameId]])->first('id'...
danimohamadnejad danimohamadnejad
5

total count and recent data in one query?

Hello. how can I get recent models and also total number of rows using same query? is that possible? thank you in advance...
kylemilloy kylemilloy
12

Many-to-many only works one way

I'm sure this is an error in my code somewhere that's filtering it out but I'm completely stuck. I have a vendors table and a products table that have a price associated wi...
Eloquent
12
118
danisemet danisemet
10

Mass Asignment

how can i store this array using mass assignment technique. array:5 [▼ "semester_id" => 1 "tahun_id" => 4 "mata_kuliah_id" => 7 "score" => array:2...
Eloquent
10
171

Eloquent update not working

For one of my tests i try to update the created_at timestamp. But this update will be completely ignored. I don't know why. The test public fun...
Eloquent
23
866
GabrielSC GabrielSC
4

whereIn result with duplicates

Good morning to everyone. I have an array of IDs with the following values [7, 28, 8, 8] (8 appears twice). When I use the array above in a whereIn('id', [7,...
Eloquent
4
1100

Strange Eloquent Behavior: Trying to get property 'name' of non-object and Object exist

I have this function that returns a value in the DB: public function getMetaValue($key) I then created a function to read a data in the DB b...
bufferoverflow bufferoverflow
5

Improve ->whereHas() query performance

I have a scope for querying the models that have a relationship with the passed category id. This scope returns all the models that have that category or subcategory relati...

Transforming SQL query to eloquent

I'm trying to transform some API endpoints that use SQL to something more eloquent. Right now, I have a series of API's that all are built on SQL which makes them a bit bri...
connecteev connecteev
5

Generating fake data (using faker) in a DB table with a 'unique' DB constraint?

Summary Is there a better way to generate fake data with a 'unique' DB constraint? Versions PHP version: PHP 7.3.5 Faker version: "fzaninotto/...
HeroVega HeroVega
2

Polymorphic Relationship Not Eager-Loading Correctly

We're currently in the process of trying to optimize some of our application's load times using eager-loading, however, we've run into an issue when trying to load relation...
Rymercyble Rymercyble
2

ordering by two numbers

hello, i'm trying to get data from db and order them by two columns group and position with ->orderBy('group') ->orderBy('position') i...
Create a New Discussion Button