Questions tagged as 'laravel-eloquent'

1
answer

Query table row by column name in Laravel?

In Laravel I want to query a record in the database for id of the table, but the code below only queries if the column nomenclature is id $prod = $this->produto->find(3) If the column name is prod_id for example,...
asked by 20.07.2017 / 22:38
1
answer

How to do sorting by two parameters with Laravel 5.4?

I am doing a descending order to list winners, however it is based on note. My search is as follows: public function getHistorico($id_avaliacao) { return $this->where('avaliacao_id', $id_avaliacao) ->orderBy('nota', 'des...
asked by 23.02.2017 / 14:30
2
answers

How to see the queries that were executed by eloquent in Laravel?

How can I find out which queries have been executed in Laravel? For example, I have the following query: $usuarios = Usuario::with('nivel')->where(['status' => 1])->get(); I would like to know which queries were executed. Can yo...
asked by 24.08.2016 / 15:09
1
answer

How to customize the return of an attribute in Laravel?

In Laravel , I know that attributes can return an object of type Carbon\Carbon (an extension of DateTime of php), if the field is created_at or updated_at. Example: $usuario = Usuario::find(1); // Não é uma string, é um...
asked by 15.03.2016 / 15:43
1
answer

Update in Laravel 5 a field receiving the value of another field from the same table

I have a configuration table in my database that has the following fields: ["id", "texto", "textoOriginal"] . Initially the values of the texto field are equal to the textoOriginal field, but the user can at any given time ch...
asked by 22.05.2015 / 23:12
2
answers

Laravel BelongsToMany

I have a user table that makes relationship with profile belongsTo , and the profile makes relationship with items from area belongsToMany , and items from area makes relationship with area belongsTo , it is bringing my item fr...
asked by 09.12.2014 / 17:58
1
answer

What is the difference between Model :: lists () and Model :: all () - lists () in Laravel?

In Laravel , we have a method that we can list fields of a table in the key-value style. I can do this in two ways So: Usuario::lists('nome', 'id'); And So: Usuario::all()->lists('nome', 'id'); The result would be: [1...
asked by 17.02.2016 / 11:47
1
answer

Is there any way to use Laravel Eloquent in the Silex microframework?

I'm refactoring a structure of a site and moving on to the Silex microframework. I would like to know if there is any way to use the Laravel Eloquent ORM to connect to the database. I read in the documentation that has how to use Doctrine,...
asked by 17.01.2017 / 11:35
2
answers

Select specific columns of two related tables

I have a relation of N x 1, Post x User , have a relationship like the following: Post.php (model): .... public function user() { return $this->belongsTo('User'); } .... What I want is to select the id and the user...
asked by 31.10.2017 / 21:55
2
answers

How to keep the foreign key constraint using softdelete?

How can I maintain the integrity of my database when I'm using softdelete ? Example: I try to delete a person that is linked to a account with a foreign key , in this is not possible because it violates the foreign key constrain...
asked by 04.11.2016 / 14:40