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 5 Time Difference

I have an application which on sign in records in time and on sign out records out time. My table has IN_TIME & OUT_TIME Example of data within those columns: IN_TIME = 16:06:46 OUT_TIME = 16:08:07 I have a controller which to my blade template file…
Dev.W
  • 2,340
  • 9
  • 38
  • 77
5
votes
1 answer

Laravel - update is incrementing the ID?

Hello guys, I'm making an API using Laravel. In one of my scripts, I make an update on a field, like this : user::where('uuid', $uuid)->update(['date' => $date]); I noticed that the primary key increments when doing this. My obvious conclusion is…
Jeremy Belolo
  • 4,319
  • 6
  • 44
  • 88
5
votes
1 answer

Change 'descendants' relationship to 'siblings' relationship

I have variants table as following: +-------------------+------------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra …
user1292810
  • 1,702
  • 7
  • 19
  • 38
5
votes
2 answers

Eloquent grouped orWhere

Currently have an Eloquent statement: $contacts = Contacts::where('lname','LIKE',$searchquery.'%') ->orWhere('fname','LIKE',$searchquery.'%') ->orWhere('phone','LIKE','%'.$searchquery) ->where('active','=',1)->get(); It is treating it…
Keith Clark
  • 609
  • 1
  • 7
  • 19
5
votes
1 answer

Laravel 5.1 eloquent relations model- how to update foreign key column?

im a beginner at laravel. never worked with framework before. i have created a database named 'tabletest'. it has two table. one is user table and other is phone table.user table has two column(id and name). phone table has 3 column(id phone and…
Noob Coder
  • 2,816
  • 8
  • 36
  • 61
5
votes
2 answers

'Where like' clause using the concatenated value of 2 columns with eloquent

I have a query that searches for a term in several columns and one of them has to be a full name. I have separated the full name in name and lastname, so I have to concat these 2 values when searching. I have this right now only searching for name.…
codiaf
  • 569
  • 2
  • 18
  • 47
5
votes
2 answers

Slim Framework and Eloquent ORM

I'm using Slim Framework together with Laravel's Eloquent ORM and this is my code: User.php class User extends \Illuminate\Database\Eloquent\Model { protected $table = 'accounts'; } index.php require_once 'vendor/autoload.php'; //…
wobsoriano
  • 12,348
  • 24
  • 92
  • 162
5
votes
2 answers

Laravel 5.1 create collection or associative array from raw DB (or just an array)

given the following table structure, I want to return either an Eloquent collection or at least convert the raw DB result to an associative array for easier iteration. buildings +----+---------------+ | id | building_name | +----+---------------+ | …
dangel
  • 7,238
  • 7
  • 48
  • 74
5
votes
1 answer

Laravel 5 Eloquent charset utf8 issues

I use Laravel 5.1 and a mysql server. I have a database with table in utf8 unicode, and my databse configuration file is like this : 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' =>…
EkinOf
  • 451
  • 1
  • 7
  • 18
5
votes
2 answers

Laravel hasMany association with multiple columns

I have two models model_1 model_2 model_1 has many model_2 Now I want to association model_1 hasMany model_2 match with multiple column. Let me give an example in raw query select ...... from model_1 left join model_2 ON (model_1.f1 = model_2.f1…
5
votes
2 answers

Accessing Eloquent relationship attributes

I have three models all related by one-to-many. Category, Subcategory and Style. I have relationships working both ways - though I seem to have a problem accessing related attributes. After my queries have ran, I'm left with this an instance of…
Mike Kaperys
  • 160
  • 1
  • 1
  • 9
5
votes
2 answers

Laravel/Eloquent 5 whereBetween not working as expected

I am using Laravel 5, and I would like get rows between two dates in my database (SQLite). I am using this command: $trackers = Tracker::whereBetween('detect_at', [$date1, $date2])->where("serial", "uhu")->get(); But I get no response. Entire…
Hydral
  • 101
  • 1
  • 1
  • 10
5
votes
2 answers

Eloquent HasMany relationship, with limited record count

I want to limit related records from $categories = Category::with('exams')->get(); this will get me exams from all categories but what i would like is to get 5 exams from one category and for each category. Category Model public function Exams()…
MePo
  • 1,044
  • 2
  • 23
  • 48
5
votes
2 answers

Retrieve all morphedBy relations

An Order have many ordered items An Order's ordered items can either be a User or Product What I am looking for is a way to retrieve all morphed objects to an Order. Instead of $order->users or $order->products I would like to do $order->items. My…
FooBar
  • 5,752
  • 10
  • 44
  • 93
5
votes
3 answers

Save multiple rows to database from dynamic forms in Laravel 5

I'm using jQuery to generate two dynamic fields. Each pair of fields is displayed on the page and can have multiple instances. On submit (not ajax), each pair of fields is saved into the their own table row along with Auth::id(). There are two forms…
Jack Barham
  • 3,197
  • 10
  • 41
  • 62