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

Table locking issues with Laravel 5.1

I can't lock MySQL tables with this query: DB::statement('LOCK TABLES imports WRITE'); It gives those exception: [Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are…
ekstro
  • 461
  • 4
  • 15
5
votes
4 answers

Casting Eloquent\Collection (Laravel) to stdClass array using Repository pattern

I'm trying to implement the Repository pattern in a Laravel 5 app by following this article. In it, the repository implementation converts the object for the specific data source (in this case Eloquent) to an stdClass so that the app uses a standard…
Vic
  • 2,655
  • 3
  • 18
  • 28
5
votes
2 answers

Select all records where a relationship count is zero using Eloquent?

In plain English: I have three tables. subscription_type which has many email_subscriptions which has many emails. I'm trying to select all email_subscription records that have a particular subscription_type, that also don't have any associated…
marked-down
  • 9,958
  • 22
  • 87
  • 150
5
votes
2 answers

CONSTRAIN Unique on Laravel 5 Schema Builder

First of all, I want to tell you, I have searched the Internet this problem and I have not been able to solve this problem. My problem is with the primary keys of my tables. I have 2 Tables, events and event_guest +-----------+ | event …
Ivan Bravo Carlos
  • 1,650
  • 3
  • 15
  • 22
5
votes
4 answers

Laravel Eloquent: inserting data

I am sending a bunch of data through post method. For now I am using a fully working solution: $dataClient = new Client; $dataClient->name = $post['client']['name']; $dataClient->address = $post['client']['address']; ... $dataClient->save(); …
be-codified
  • 5,704
  • 18
  • 41
  • 65
5
votes
1 answer

Laravel 5 hasManyThrough Pivot Table

I am trying to create a relationship to access a table called comments through a model called grade, loaded through the students in the grade Both the Grade and Student models belongToMany of the other From my understanding, it is not possible to…
5
votes
5 answers

Eloquent update and get record back

When I usually update a record, I do $myObject->update(['field' => 'value']); And that updates both the database and my instance $myObject. However, sometimes, I need to do bulk updates, so I use the model facade and do $result =…
user391986
  • 29,536
  • 39
  • 126
  • 205
5
votes
2 answers

Correct way to run a select query from blades in laravel 5 using eloquent

What is the Correct Way to retrieve a column value based on certain select filter on a Model variable availed by compact method inside the blade. (Larevl 5) I read that Its a bad practice to query database staright from views, and hence i followed…
echoashu
  • 912
  • 3
  • 14
  • 31
5
votes
2 answers

Laravel query. Where unique

I got database table like this: **job_id** 5 5 5 6 6 7 8 8 I want to write query, which could select only unique id's. By saying unique I mean select only these values once: 5, 6, 7, 8 Thanks in advance!
Evaldas Butkus
  • 635
  • 4
  • 12
  • 32
5
votes
2 answers

Automaticly make a profile when user registers (Laravel 5)

I'm trying to make a profile page for my registered users. On this page the Auth\User data will be displayed (Name, Email) but also extra profile information (city, country, phone number, ..). I've already made the one to one relationship but I'm…
Pex
  • 519
  • 2
  • 12
  • 30
5
votes
1 answer

Laravel Fluent vs Eloquent

First question: Why does Fluent return an array: return DB::connection('mysql')->table('cards') ->where('setCode', '=', $setcode) ->get(); While Eloquent returns an object: return Card::where('setCode', '=', $setcode) ->get(); The data…
Howard
  • 3,648
  • 13
  • 58
  • 86
5
votes
3 answers

Laravel call method once model loaded

I am trying to check in the constructor of a model if the currently authenticated user is allowed to access the given model, but I am finding that $this from the constructor's context is empty. Where are the attributes assigned to a model in Laravel…
Brad Reed
  • 443
  • 7
  • 16
5
votes
0 answers

Pass variable into global scope and determine if query output is null Laravel

I've translation models and I want to run Global query scope that determine the current locale and return the corresponding value upon it or fall back into English if the translation doesn't exist in DB. I've created a global scope for this purpose…
5
votes
1 answer

Eloquent firstOrNew causes duplicate entry error

I'm trying to find an item and update it if it exists, or to create a new one if it does not exist. However, for some reason it seems to be trying to create a new object instead of updating in the event that that already exists in the database. …
Marcel Gruber
  • 6,668
  • 6
  • 34
  • 60
5
votes
2 answers

Get database credentials from master database, then connect to different database

I have an instanced web application that uses different databases for every instance but uses the same files. What I want my application to do on boot: Get database credentials from master instance table. This instance table is in the default…
Basaa
  • 1,615
  • 4
  • 20
  • 41