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
1 answer

How to catch model events in pivot tables

I want to track (record) the changes made to each database row. This means, saving a log of each action (insert, update, delete) made to each record of each table. This issue is solved for models, as they extend from a BaseModel and I'm using model…
Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
5
votes
1 answer

Laravel form binding with one to one relationships

I have an Account model that has a polymorphic relation to an Address model. This is set up as a one-to-one releationship set up like so: Account: public function address() { return $this->morphOne('Address', 'hasAddress', 'add_hasaddress_type',…
Troncoso
  • 2,343
  • 3
  • 33
  • 52
5
votes
2 answers

Guide me implementing Oauth2 PHP server using thephpleague library

I am using Slim Framework With Eloquent ORM. Trying to implement https://github.com/thephpleague/oauth2-server but I am totally confused how to do this. After adding this with composer, I created database with sql file provided in this package. Now…
Tejas
  • 2,215
  • 2
  • 18
  • 27
5
votes
1 answer

Merging results from belongsToMany and belongsTo relationships in Eloquent

In my Image model I have two relationships with my Article model, one many-to-many and one one-to-many: public function articlesAlbums() { return $this->belongsToMany('Article', 'article_image', 'image_id',…
Thomas Jensen
  • 2,138
  • 2
  • 25
  • 48
5
votes
1 answer

Laravel Eloquent - sync() on a Morph relationship

It seems like there is no sync() function for morph tables on Laravel. I have two tables avails and questions. questions is a morphMany table. I want to use the sync command, and this is what I…
Kousha
  • 32,871
  • 51
  • 172
  • 296
5
votes
2 answers

Eloquent Complex Joins

i have made a scope public function scopeCollaborative($query){ return $query->leftJoin('collaborative', function($join){ $join->on('imms.phone2', '=', 'collaborative.phone') ->orOn('imms.phone', '=', 'collaborative.phone') …
Maximilian Prepl
  • 402
  • 4
  • 10
5
votes
2 answers

Laravel many to many loading related models with count

I am trying to link 4 tables and also add a custom field calculated by counting the ids of some related tables using laravel. I have this in SQL which does what I want, but I think it can be made more efficient: DB::select('SELECT …
Ego_I
  • 350
  • 3
  • 14
5
votes
0 answers

Pagination doesn't work when there is orderByRaw

thanks for reading. I have a method that take data from a table, with an orderByRaw sentence. Everything is ok unless when I want to do a pagination, which without the orderByRaw works perfectly. I've seen here a solution:…
user3592436
  • 461
  • 2
  • 4
  • 13
5
votes
2 answers

Don't use prepared statements in Laravel Eloquent ORM?

Can I have Eloquent ORM run a query without using prepared statements? Or do I have to use whereRaw()? I need to use a raw query because I'm trying to interact with InfiniDB, which lacks support for prepared statements from PHP. At any rate, all…
Kevin Pei
  • 5,800
  • 7
  • 38
  • 55
5
votes
1 answer

Laravel: conflict between model name and built-in facade

I have a Model in my Laravel app called Event. As I just discovered, this creates a conflict between my model and Illuminate\Support\Facades\Event, a built-in facade. The obvious solution here is to either change the name of my Model, which is not…
ewok
  • 20,148
  • 51
  • 149
  • 254
5
votes
1 answer

Laravel Custom Pivot Table relationship and eager loading?

I am having problems with creating a schema / model for one of my projects and would like to get some help here. I have 3 tables currently : accessories , products and a pivot table product_accessory
yulun
  • 260
  • 1
  • 6
  • 21
5
votes
3 answers

Laravel Pivot table id column

In Laravel and Eloquent you can use ManyToMany-Relations with a pivot table. The problem in my case is the automatic ID of the pivot row. Can I change how the ID is generated? I want to use UUIDs for that matter. For other Objects you can just…
Tobias Krischer
  • 354
  • 4
  • 11
5
votes
3 answers

Laravel Model Event updating() not firing

class Profile extends Eloquent { protected $fillable = array('name', 'last_name', 'website', 'facebook', 'twitter', 'linkedin', 'google_plus'); public static function boot(){ parent::boot(); …
Mauro Casas
  • 2,235
  • 1
  • 13
  • 15
5
votes
2 answers

Delete Elequent records older than 60 minutes

How can I delete all Eloquent Records in a database where the created_at or updated_at field is older than 60 minutes? (or any amount of time for the example) edit: posted solution as answer as @Alexxus suggested
Barry127
  • 1,212
  • 1
  • 12
  • 23
5
votes
1 answer

Laravel Creating default object from empty value when creating an Eloquent object

I'm trying to save an object to the database for a game I'm building on a website, but I keep getting this error: Creating default object from empty value Here's the code I'm using: foreach( $input['items'] as $key=>$itemText ){ $item =…
Chris
  • 4,277
  • 7
  • 40
  • 55