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

Laravel Eloquent: merge model with Input

I would like to know how it is possible to merge data from Input::all() with a model and save the result. To clarify: I would like to do something like below: $product = Product::find(1); // Eloquent Model $product->merge( Input::all() ); // This…
user3518571
  • 407
  • 2
  • 5
  • 11
5
votes
2 answers

Laravel float variable changing value when adding to database

Theory I have quite a comprehensive coordinates list (Latitude and Longitude to 7 decimal places), which I want to continually add to. In order to stop data duplication, for each coordinate that's trying to be be inputted, I want to check the…
user860511
5
votes
4 answers

Laravel Eloquent - $fillable is not working?

I have set the variable $fillable in my model. I wanted to test the update functionality, and I get this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_method' in 'field list' (SQL: update positions set name = Casual Aquatic…
Kousha
  • 32,871
  • 51
  • 172
  • 296
5
votes
1 answer

Why is Laravel trashed() method not found>

I'm trying to use the soft delete functionality of Elequent ORM in Laravel 4.1 Deleting records works as expected, however when I search for results using withTrashed() and then check to see if it was a soft deleted record using trashed() I get the…
user1462432
  • 233
  • 3
  • 9
5
votes
3 answers

Human Readable Timestamps Laravel 4 with pivot tables

Is there a way to display the created_at and updated_at timestamps in human readable format if they are used in a pivot table? Im new to the whole pivot table laravel thing, but right now i am using a pivot table to store user comments on individual…
jackthedev
  • 417
  • 8
  • 21
5
votes
2 answers

Get MySQL table columns using Eloquent in Laravel

How would I get inside of a custom model the columns for a specific MySQL table using Eloquent in Laravel I was trying DB::query("SHOW COLUMNS FROM " . $table) but without any success
fefe
  • 8,755
  • 27
  • 104
  • 180
5
votes
2 answers

Get ID from Laravel eloquent query through a relationship

A company hasMany users, this relationship is achieved through a pivot table. I want to be able to get the company.ID of the company an individual user is related to: $company_id = User::find(Auth()->$id)->companies->get('$id'); Unfortunately, I…
user860511
5
votes
1 answer

Optimizing Laravel's Eloquent models

There are 3 MySQL tables in database: Products: id | name Product prices: product_id | currency_id | price Currencies: id | mark And Laravel's Eloquent models look like this: // Product.php class Product extends Eloquent { protected $table =…
arnisritins
  • 1,250
  • 3
  • 15
  • 23
5
votes
1 answer

laravel/eloquent mutators/accessors in a pivot table

Well, I think the title explains most of it. Lets get right into it! Blank Model: class Blank extends Eloquent { protected $table = 'blanks'; protected $softDelete = true; protected $hidden = array(); /** * Get associated…
KernelCurry
  • 1,297
  • 1
  • 13
  • 31
5
votes
2 answers

Make Laravel use MySQL default value on insert/update

I've noticed that, in Laravel, (when using $model->fill(Input::all()), not that it matters how the data comes in), empty fields (empty in a form) come through as an empty string (''). That makes sense, as that's how it's delivered from browser to…
alexrussell
  • 13,856
  • 5
  • 38
  • 49
5
votes
2 answers

Saving a model with multiple foreign keys in Laravel 4

I understand that in order to save a foreign key, one should use the related model and the associate() function, but is it really worth the trouble of going through this $user = new User([ 'name' => Input::get('name'), 'email' =>…
Nicolas
  • 2,754
  • 6
  • 26
  • 41
5
votes
3 answers

Eloquent - use unique string or unique int as id

For my users table, Eloquent lets me use an id with increment: $table->increments('id'); That is just fine. Every new user will get their id, 1, 2, 3, etc. However the id should be an automatically assigned string or integer. I want the user not…
Shlomo
  • 3,880
  • 8
  • 50
  • 82
5
votes
2 answers

Laravel postgresql case insensitive

I'm coding a web app using Laravel 4.1 and Postgresql as database. The db is case sensitive, but i'd like to make it case insensitive because, i.e., when a user is logging he should be able to access using upper case or lower case email address…
5
votes
1 answer

3-way Relationships with Laravel and Eloquent

I've already posted this on the laravel forums but nobody was able to offer any help. Thought I'd post here for a second opinion. I need a little advice/help with how to structure my models. Here's what I'm trying to do A User can be a member of…
Mcg1978
  • 464
  • 6
  • 19
5
votes
2 answers

Database Best Practice with multiple similar entities

I have a very simple question concerning 2 alternatives from which I do not know which one to choose. I have entities which can be "contacts". A 'contact' can have multiple e-mail adresses, multiple phone numbers and multiple addresses. In my data…
Matthias S
  • 3,358
  • 3
  • 21
  • 31