Most voted "laravel-eloquent" questions
Eloquent is the Laravel ORM. Use this tag for questions specific to the use of Eloquent and its related models
Learn more…425 questions
Sort by count of
-
13
votes2
answers641
viewsDoubts with relationships in Eloquent
Guys I’m making a belongsToMany to recover several Users that are related to a Item. It returns me in the all array Users correctly, but I need to make a hasOne of each User(created on the model…
-
10
votes1
answer13822
viewsWhat’s the simplest way to make an IS NULL with Eloquent?
I saw tutorials on the internet that way you had to make a IS NULL is the following: Remessa::where('campo', 'IS', DB::raw('NULL'))->get(); But I was wondering about this, because if a ORM is…
-
7
votes2
answers744
viewsHow to create a Grouped List in Laravel 4 from an entity with self-relationship
I’m trying to create a select box com \Form::select() (grouped list) in Laravel 4 and I have the following entity: Items id = id do item nome = nome do item pai = fk dessa mesma entidade I already…
-
7
votes2
answers394
viewsGet inverse relationship with Laravel
I am creating a forum system that is divided by sections. Each section contains categories, each category contains topics. Ex: Administração _ |_Regras da do fórum |_Sugestões e críticas…
-
7
votes2
answers4496
viewsConsultations between tables with Eloquent - Laravel 5
Good, I have the following problem when using Laravel 5 in the relationship of tables: I have these 4 tables (hypothetical names to illustrate the problem): Using the Laravel 5 models I connected…
-
7
votes2
answers611
viewsWhat is the purpose of using UUID (version 4) as "Primary key"?
I have noticed that some places have switched the ID (generated by autoincroment, depending on SGDB) by UUID, usually use version 4 of UUID which is based on a pseudo-random system, the question is…
database entity-framework laravel-eloquent uuidasked 4 years, 2 months ago Guilherme Nascimento 98,651 -
6
votes1
answer74
viewsConflicts with the Confideuser class
In my model User, left my protected $table = 'usuarios' and in auth.php the same thing, but when calling the method save() of the Eloquent, he recognizes the table 'users' and not 'users' as I…
-
6
votes1
answer1511
viewsSelf relationship in Group table with Laravel and Eloquent?
I have a table of grupo with the fields: id (int not null auto-increment) Description (sweep) grupoid (int null) How would it be: 1) to migration corresponding to that table? 2) the creation of…
-
6
votes1
answer324
viewsMounting a query with Laravel
I’m studying the structure of the Laravel from this example already ready => beast. In the project there is the repository userRepository with the following structure: <?php namespace…
-
5
votes1
answer355
viewsDoubt with relationship One to Many
I have two tables, produtos and categorias. In my view of produtos i want to show the category name of that product, not its code. Model de Categoria Category.php namespace…
-
5
votes1
answer685
viewsCatch the Average of a Relationship Table FieldMany to Many Laravel Eloquent
I have a relationship Many to Many and in the relationship table the field "value". How do I bring the media from this field using the Eloquent? Example: Tabela A a_id Relationship Table a_id c_id…
-
5
votes2
answers604
viewsRelationship on-to-one in auxiliary table using Laravel
In the application I am working the database is built on the part of users, as follows: user 1 -------> 1 user_address 1 <-------- 1 address In the user table there is no column referencing…
-
5
votes1
answer1200
viewsHow to create a database automatically in Laravel with all tables?
Well I need help in a problem, I am developing a system for the first time in Latin and I need to create a database for each user registered in my system, these databases should have the same tables…
php database sqlite laravel-eloquent laravel-5.3asked 5 years, 5 months ago Igor De Moraes Sampaio 79 -
4
votes1
answer128
viewsDistant relationship with Laravel
I have this table structure and would like to know if who posted the thread or the reply is Member or moderator, but I couldn’t structure a relationship that works, someone can help me? forum id -…
-
4
votes3
answers992
viewsReturn only the newest record of each author
I have a table with the following fields: id, texto, autor_id, data I need the records to be grouped by autor_id (because it has several texts with the same author) and return me in ascending order…
-
4
votes3
answers1822
viewsI cannot access object property. Laravel/Eloquent ORM
I cannot access the properties of the related object. Well, I have a class calling for FileClass, she has the following relationship with class FileServico: Fileclass.php public function…
-
4
votes1
answer624
viewsLaravel 5.2 with pagination
I have the following function inside the controller public function home() { $igrejas = Igreja::paginate(3); $igrejas->setPath('igrejas'); return view('admin/igrejas/home')->with('igrejas',…
-
4
votes3
answers145
viewsBlade default value Laravel 5.2
I have the following code <strong class="primary-font">Complemento</strong> <p>{{ $produto->complemento or 'Esta produto não tem complemento' }}</p> I need that if the…
laravel laravel-eloquent laravel-blade laravel-5.2asked 8 years, 3 months ago Danilo Tiago Thai Santos 409 -
4
votes3
answers684
viewsUpdate registration with Laravel 5.2?
I have the following function : public function alterar($id) { $produto = Produto::find($id); $params = $request->all(); $produto->fill($params)->save(); return…
-
4
votes2
answers3070
viewsHow to see the queries that were executed by the eloquent in Laravel?
How can I find out which queries were executed in Laravel? For example, I have the following query: $usuarios = Usuario::with('nivel')->where(['status' => 1])->get(); I would like to know…
php laravel laravel-5 laravel-4 laravel-eloquentasked 8 years, 3 months ago Wallace Maxters 102,340 -
4
votes2
answers719
viewsHow to keep foreign key restriction using softdelete?
How can I maintain the integrity of my database when using softdelete? Example: try to exclude a person which is linked to a account through a foreign key, in normal ways this will not be possible…
-
4
votes1
answer122
viewsDo a Hasmany per date with Laravel 5.3?
Is there any way to make a HasMany bringing records by date? public function despesas() { return $this->hasMany(Despesa::class); //registros apenas desse mês } I tried to use the following, but…
-
4
votes1
answer7065
viewsLEFT JOIN com AND no Eloquent Laravel 5
I have a query with Left Join with AND I’m not able to implement it in Laravel 5. A snippet of the query: LEFT JOIN visitante v ON a.codigo = v.id AND v.data BETWEEN '2015-06-01' and '2016-05-31'…
-
4
votes1
answer13616
viewsHow to create a cron in Laravel?
I have to create a Cron on Laravel to send emails every 24 hours. I’m supposed to upload data from the bank. So after a query in the database cron should send the email with the query data.
-
4
votes1
answer1650
viewsSearch for relationship whereHas Laravel?
I have a Query in my Criteria that returns the id belonging to the relationship amid models if ($this->request->has('notin_portal')) { $portal = $this->request->get('notin_portal'); if…
-
4
votes1
answer1002
viewsSave Relationship 1:1 on Laravel 5.3
In my scenario, I have tables of users and teachers, where a teacher has a user, so I have a relationship 1:1. Migrations: create_users_table Schema::create('users', function (Blueprint $table) {…
-
4
votes2
answers851
viewsSort items from a Collection from a preset value
I have a Collection of the Eloquent and I would like to order it through two fields at the same time being one of them a predefined value. Ex.: this one Collection has several objects of the type…
-
4
votes3
answers640
viewsHow to resolve foreign key error 150 in Migration with Laravel?
I’m having trouble creating the foreign key in Migration. I am working with PHP, LARAVEL 5.3 and MYSQL. You’re making the following mistake: Below is my code: Table Migration categs class…
-
4
votes2
answers397
viewsHow do I search with Query Builder in Laravel?
I need to display the name of the doctor who requested a patient report, however, with Laravel I tried to show this information on View thus: {{laudo->paciente->medico->nome}} Then I…
-
4
votes2
answers1661
viewsLaravel: Cannot add Foreign key Constraint
I have two tables, the table users and empresas, with Model User and Empresa respectively. A user registration can manage a company, and for that, I need to define which id the user will access in…
-
3
votes2
answers1735
viewsDate being recorded wrong in m-d-Y bank instead of Y-m-d
I set the date format for viewing to "d-m-Y", while the recording format is from the "Y-m-d" bank". However at the time of recording in the database, something happens and the data is going in the…
-
3
votes1
answer759
viewsRelationship in Laravel/Eloquent ORM
I have a problem. I need to return the values of a relationship, however, presents the following error: ErrorException Undefined property: Illuminate\Database\Eloquent\Collection::$fileServico My…
-
3
votes2
answers263
viewsLaravel Belongstomany
I have a user table that makes relationship with profile belongsTo, and the profile relates to area items belongsToMany , and area items makes relationship with area belongsTo, he is bringing my…
-
3
votes1
answer1555
viewsWhat is the difference between Model::lists() and Model::all()->lists() in Laravel?
In the Laravel, we have a method that we can list fields from a table in the key value style. I can do it two ways Thus: Usuario::lists('nome', 'id'); And So: Usuario::all()->lists('nome', 'id');…
-
3
votes2
answers2174
viewsSort results by a relationship column in Laravel 4
Currently I have some methods that used together allow me to make requests to my application controlling the "withs", "Orders" and such via querystring. I can do, for example: GET…
-
3
votes1
answer761
viewsLumen and Firebird Database
Lumen and Eloquent can be used in a Firebird database that is already used by another application, without the ORM making changes to the database structure? Another detail: it is possible to access…
-
3
votes1
answer1219
viewsUpdate on 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 field values texto are equal to the field textoOriginal, but the user can…
-
3
votes2
answers1412
viewsList Tree Categories in Laravel 5.1
I’m starting with Laravel 5.1 and I’m a little lost yet. I need to list categories, subcategories and "sub-subcategories". Table: Categorias ------------------------ id | int nome | varchar…
-
3
votes1
answer395
viewsIs there any way to use Laravel Eloquent in the Silex microframework?
I’m refactoring a website structure and moving on to the Silex microframework. I wonder if there is any way to use the Laravel Eloquent ORM, to connect with the database. I read in the documentation…
-
3
votes1
answer438
viewsHow to sort by two parameters with Laravel 5.4?
I am making a decreasing order to list winners, but it is based by note. My search is as follows: public function getHistorico($id_avaliacao) { return $this->where('avaliacao_id', $id_avaliacao)…
-
3
votes1
answer635
viewsHow to customize the return of an attribute in Laravel?
In the Laravel, i know that attributes can return an object of type Carbon\Carbon (an extension of DateTime php), if the field is created_at or updated_at. Example: $usuario = Usuario::find(1); //…
-
3
votes1
answer164
viewsHow to get records from a table when there is no relationship with another table in Laravel?
In Laravel, when I want to get data from a table that contains some relationship, or when I want to get the data from a condition of a related table, for example, usuarios that contains livros, I…
-
3
votes1
answer453
viewsSee table row by column name in Laravel?
At Laravel I’m looking for a record in the database by id table, but the code below only consults if the nomenclature in the column is id $prod = $this->produto->find(3) If the column name is…
-
3
votes1
answer2023
viewsWhat’s the point of a Cope on the Laravel?
I saw in the documentation of Laravel an explanation about the use of Eloquent. There I saw a part where he talks about Local and Global Scopes. As I do not know much English, I was left with some…
-
3
votes1
answer919
viewsHow to use Laravel paginate with a manual query?
I have a query manual on my model, and I want to return to view of blade the result of this paging query. Is there any way? Model class Ticket extends Model { protected $fillable = [ 'id', 'title',…
-
3
votes1
answer994
viewsCall to Undefined method Illuminate Database Query Builder::lists()
I’m having a problem creating a list of types for my project, for some reason in others Controller worked perfectly but in this unfortunately not. I’m doing the method create of my Controller public…
-
3
votes2
answers2510
viewsPass string to uppercase - Standard
Good afternoon. I have the following code that saves perfectly. public function store(Request $request) { $this->validate($request, [ 'servidor' => 'required|unique:servidors|max:255', //…
-
3
votes1
answer6521
viewsUsing Count() in Laravel
I have a controller who plays for my view the total number of courses registered in the portal. My doubt is due to the operation of the method count(). For example, the output of both instructions…
-
3
votes1
answer340
viewsHow to change Laravel’s relationship keyword
I have the following problem, I entered a project where the database already existed and is in production, so all foreign keys of this bank are with the nomenclature fk_ and the Eloquent of Laravel,…
-
3
votes3
answers5888
viewsDifference between the create and Fill method - Standard
I was developing a web service with Laravel, and I realized that I can save the data in my database in two ways: Product::create($request->all()); or else: $product = new Product();…