Questions tagged [eloquent]

The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

The Eloquent included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

Resources

26966 questions
5
votes
2 answers

Add item to select box with an Eloquent collection

I have a select box on a form which uses data that is listed from an Eloquent model (Laravel 4): $campuses = Campus::lists('name', 'id'); And the form: {{ Form::select('campus_id', $campuses) }} However, I would like to have the first option on…
Dwight
  • 12,120
  • 6
  • 51
  • 64
5
votes
1 answer

How to have different seeders per environments in Laravel 4?

I have a simple question but I haven't found an answer in the web. Maybe my keywords are false. So I am developing an app in Laravel 4. And I need to seed the database with different values according to the current active environment. So for…
Reflic
  • 1,411
  • 15
  • 25
5
votes
3 answers

Eloquent ORM Performance

I have just been testing the performance Eloquent ORM in Laravel and was shocked to find a simple query taking over 3 seconds to perform compared to the normal Laravel query which finished in 0.1 seconds. I'm only returning 1500…
Craig Morgan
  • 942
  • 2
  • 11
  • 27
5
votes
2 answers

Laravel inserting and retrieving relationships

I'm working on a project built on Laravel 3, and I'm trying to see if I can shorten the code for working with relationships (better ways of doing the following) user controller create user function $newUser = new…
Alex
  • 7,538
  • 23
  • 84
  • 152
5
votes
1 answer

Eloquent makes a lot of queries

I just started playing with Laravel 4 and Eloquent. I have a blog table and lots of other related tables to it: blog <- main info about the blog record blog_lang <- translations for each blog record blog_categories <- name speaks for…
user2433934
5
votes
3 answers

how to make query with substr in eloquent (laravel 4)?

I have this query: select substr(id,1,4) as id from meteo.a2012 group by substr(id,1,4) I just want to take first 4 numbers to my id row, but I'm trying to do in eloquent, how I do? Thanks.
Carlos Suñol
  • 2,643
  • 2
  • 15
  • 10
5
votes
1 answer

Many to many relationships with taxonomy in Eloquent

I'm using Laravel 4. I have many to many relationships in my system. And I choose to use Wordpress taxonomy table scheme. But how can I make models relationships with Laravel 4 Eloquent ORM? Here is my database tables; Table…
musa
  • 1,457
  • 18
  • 37
5
votes
2 answers

Laravel Eloquent find returning null

I'm trying to retrieve a record from my database using Eloquents find method, however, it's unexpectedly returning null. If I run the query manually on the database then it returns the expected record. I'm using the following in Laravel: $support =…
Jake Stubbs
  • 247
  • 2
  • 10
4
votes
1 answer

Eloquent ORM: Factory not reusing the already created model for a many-to-many relation

I'm modeling and seeding the following models using Laravel 9 and Eloquent: Organization (1-n) organizations_users (pivot) User (1-n) To seed that model, I followed the documentation and used has() and recycle()…
maxime
  • 1,993
  • 3
  • 28
  • 57
4
votes
2 answers

How to order by child / parent column with Eloquent?

I have a table called terms which contains the following fields: id | name | slug | taxonomy | parent_id This is the current datasource: id | name | slug | taxonomy | parent_id 1 Pop pop category null 2 Rock rock category null …
sfarzoso
  • 1,356
  • 2
  • 24
  • 65
4
votes
5 answers

How to log every query from multiple connections in Eloquent (outside laravel)

I use multiple database connections in my app, one SQLServ, and another MySQL. I want to debug every query from both servers sequentially. therefore rather using Manager::getQueryLog() i need to use Event::listen. I use SlimFramework, with…
Egy Mohammad Erdin
  • 3,402
  • 6
  • 33
  • 57
4
votes
2 answers

Laravel: Too few arguments to function when I want to update my database

I have to develop a reservation system for a hotel. You first have to create a user and than you can make a reservation. There is an option to edit the registered users but that is the part where I'm stuck. I follow a very good tutorial but at the…
user18601213
4
votes
0 answers

Getting related failed batch jobs in Laravel

I have a laravel application which uses Batch Jobs to push a bunch of orders to an external system. For one import batch, I create an Import entry in the db and associate all orders to it which should be pushed. This allows me to show the current…
kolaente
  • 1,252
  • 9
  • 22
4
votes
2 answers

Laravel left join check if a conditon is greater than a count

I would like to check a limit in number of user payment where a limit is set on user table. So i have the following database structure table user id,name,...,pay_limit and payment table table payment id, user_id, payment_ref So i have created…
Geoff
  • 6,277
  • 23
  • 87
  • 197
4
votes
0 answers

bug in laravel 8.4? belongsToMany relationship objects not saved inside transaction

I have a simple transaction structure and a belongsToMany-relationship between 2 models user and sponsoring. I found out that the relationship data are not saved in the pivot table, when I wrap it inside a transaction. Without a transaction it works…
realphil86
  • 41
  • 1
1 2 3
99
100