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
3 answers

Laravel Eloquent all with relationship

How can I get all data from my tables with relationship in Laravel? So, I have table like: *users* id username password ... *address* id address user_id ... If I call my eloquent model with Address::all() I get response with user_id, and I want to…
Kolesar
  • 1,265
  • 3
  • 19
  • 41
5
votes
2 answers

Laravel 4.1 Eloquent - Filtering a relationship collection

I am having problems filtering a relationship using laravel 4.1 hasWhere. Iteration 1 - Get all posts: Done $posts = Post::all(); Iteration 2 - Get all posts lazy load comments: Done $posts = Post::with('comments')->get(); Iteration 3 - Get only…
Gravy
  • 12,264
  • 26
  • 124
  • 193
5
votes
1 answer

Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation from model call by not view in Laravel 4

I have a model, Ability, which belongs to another model AbilityType. belongsTo('AbilityType'); } public function name() { …
kaimerra
  • 331
  • 3
  • 4
5
votes
1 answer

Laravel Model Relations between 3 tables

I am currently trying to make a relation between 3 tables. Users uid username Groups gid groupname GroupMembers uid gid With eloquent ORM, how do I get the Groups of a User? With just 1 line of query I wanted to return a…
madziikoy
  • 1,447
  • 7
  • 22
  • 32
5
votes
1 answer

Batch Insert Objects With Relations in Laravel-4

I've come into a situation where I need to batch-save objects with their related objects in laravel 4. Essentially what I am doing is a bulk insertion of objects where each object can have many tags (many-to-many relation). Here is some sample code,…
Gimli
  • 498
  • 1
  • 3
  • 14
5
votes
2 answers

Up vote and down vote in Laravel eloquent

I want to create an up vote and down vote system for my website where a unique user can vote up/down for one post and next time he only allow to opposite to get off from database and after that he again can up or down vote. In this case I…
Sagiruddin Mondal
  • 5,407
  • 2
  • 29
  • 44
5
votes
6 answers

Laravel 4 model unit test with Codeception - Class 'Eloquent' not found

I'm trying to use Codeception to run my Laravel 4 unit tests. Running a test for a simple class with no dependencies works fine. But when I instantiate a model which depends on Eloquent, I get this fatal error: PHP Fatal error: Class 'Eloquent' not…
mtmacdonald
  • 14,216
  • 19
  • 63
  • 99
5
votes
2 answers

In Laravel how to use snake case for database table columns and camel case for model attributes

I am new to laravel 4 and I am trying to create a rest API following best practices defined by Apigee. One of the best practice defined by apigee is to use camel case for json attribute keys, this way when using the API in Javascript the…
Michael
  • 508
  • 6
  • 16
5
votes
2 answers

Eloquent ORM "standalone" DB::raw fails

For a project I'm working on, I'm using the Eloquent ORM standalone, as explained on this page. Everything is working fine, except that I can not use DB::raw in my code. I got the following PHP error: Fatal error: Class 'DB' not found That is…
trizz
  • 1,447
  • 12
  • 27
5
votes
2 answers

Laravel model event saving is not firing

I'm trying to simulate what Ardent package is doing. Which is validating a model right before saving. I've created this BaseModel (According to Laravel Testing decoded book). And added this code : class BaseModel extends Eloquent { protected…
Rafael Adel
  • 7,673
  • 25
  • 77
  • 118
5
votes
5 answers

Unable to create a model with Eloquent create method. Error telling MassAssignMentException

I have created a model named, Author. I tried creating a model with the help of eloquent create method like this: public function postCreate(){ Author::create(array( 'user' => Input::get('user'), 'info' => Input::get('info') …
Nirmalz Thapaz
  • 925
  • 4
  • 13
  • 28
5
votes
1 answer

How to use Laravel Eloquent ORM to make an or statement

How to use Laravel Eloquent ORM to make an OR statement? I know I can make multiple select like this (AND) Order::where('id', '<', $myid)->where('finance','ok')->get();
katerinaMark
  • 53
  • 1
  • 3
5
votes
3 answers

How can I implement model revisions in Laravel?

This question is for my pastebin app written in PHP. I did a bit of a research, although I wasn't able to find a solution that matches my needs. I have a table with this…
Sayak Banerjee
  • 1,954
  • 3
  • 25
  • 58
5
votes
1 answer

How to use DATEDIFF function with Eloquent?

Here is my code for selecting reservations: Reservation::select(array( 'obj_id', 'name', 'surname', 'date_from', 'date_to', 'days', 'status', 'slug', 'payable' )); My question is how to change 'days' to get…
Maciej Płocki
  • 362
  • 2
  • 7
  • 18
5
votes
1 answer

Eloquent ORM / Laravel - use custom pivot table structure

I'm trying to build a Laravel app using a customized database structure. I have tables types, units, content, and a pivot table called relations. The structure of the relations table is such: --------------------------------------------- | id |…
Томица Кораћ
  • 2,542
  • 7
  • 35
  • 57