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
-
1
votes0
answers213
viewsInserting data in the 1:N - Laravel 5 ratio side 1
I have the following tables, Condominios and CondominiosTaxas, that are a relationship 1:N , respectively, my relationship in the model Condominio: public function Taxas() { return…
-
1
votes1
answer289
viewsMore of a relationship with the table below
I have a Receivables table that has a relationship with the Customer Table and TWO relationships with a Chart of Accounts table* I searched the Eloquent documentation but couldn’t find out how to…
-
1
votes1
answer6901
viewsUse sum with Eloquent
I have the following appointment: SELECT P.ID ,P.NR_CRACHA CRACHA ,P.NM_CLIENTE NOME ,E.DS_EMPRESA EMPRESA ,SUM( R.VL_PRECO ) VALOR FROM registro R JOIN pessoa P JOIN empresa E WHERE P.CD_PESSOA =…
-
1
votes1
answer445
viewsFind the best-selling products (Laravel / eloquent)
In the Table, assuming there is a 'Product' model (whose table is products), an 'Account' model (whose table is accounts), and an N:N relationship between accounts and products, in the Product…
-
1
votes0
answers228
viewsHow to create Foreignkey without data with Windows
I’m creating a system and I have two columns: empresas and usuarios. The usuarios.id_empresa makes is the key of empresas.id_empresa, however, some data from the two tables are filled in…
-
1
votes1
answer576
viewsRedirect after update Readable
I’m working on a project with Laravel and I came across a problem. After Update I want to redirect the user to another specific page. In the update function of my Controller I have this code: public…
-
1
votes1
answer124
viewsKeep id and id_user equal on updateOrCreate
Hi, using the Slim Framework for php, I’m trying to make a updateOrCreate: $eventos = Eventos::updateOrCreate( ["id" => $id, "id_usuario" => $id_usuario], ["nome" => $nome, "descricao"…
-
1
votes0
answers48
viewsOrganize json with Eloquent
My question is this: I want to organize my json for me to consult the table Animal and Hacienda, but organized, example: { "animais": { "id": 1, "nome": "Mimosa", "data_nascimento": "2017-04-11…
-
1
votes0
answers49
viewsquery with Many-to-Many polymorphic Laravel?
I have a polymorphic m-m relationship in my bank where: class(id, name) student(id, name) Lesson(id, name) classeable(classe_id, classeable_id, classeable_type) a class has several Students and…
-
1
votes1
answer537
viewsError when connecting with sqlite in the Laravel
Internally everyone is working, migrations, tinker, sqlite3, but in the server application it always queries the mysql instead of the sqlite for all operations, ie he is using Connector.php instead…
-
1
votes2
answers242
viewsConsultations in Laravel
I’m trying to run a query on Laravel, in the terminal works perfectly, but when I insert in the Laravel, the same returns me empty, example: Consultation: SELECT MAX(positions.id), devices.name,…
-
1
votes1
answer3131
viewsHow to do Inner Join with Laravel?
I am studying Laravel and I’m not getting it make/understand how to do join and present the data. All students who are in a class with the names, class code and description of the final situation.…
-
1
votes0
answers302
viewsLaravel: how to insert in the database asynchronously?
I am developing a site in PHP, using Eloquent for database, and I have a certain problem of slowness in the time of the user to log in to the database. What I mean is... The user is taking almost 3…
-
1
votes0
answers308
viewsCRUD - LARAVEL 5.6
I am developing a CRUD and in my controller I have create function: public function create() { $neighborhood = new Neighborhood(); $city = new City(); return view( view: 'admin.cities.create',…
-
1
votes1
answer1300
viewsForm select with Laravel
I have this code working, but I wonder if there would be a more elegant way to write the following code in the view, through the Laravel formats: <div class="row"> <div class="col-xs-12…
-
1
votes1
answer34
viewsCode reduced to Insert
Say you have the following fields in the users table: ID,NOME,USUARIO,LOGIN and SENHA For me to enter a record in the table I do the following $usuario = new Usuario(); $usuario->nome = 'Carlos…
-
1
votes0
answers43
viewsRelationship no Laravel
Speak guys, I’m starting to use the Standard and I’m having a problem selecting some data. I have the following tables: users, jobs, projects, job_user. The list of users and jobs is of many to many…
-
1
votes1
answer78
viewsEloquent does not return the same results as SQL
I have that code SQL which when running straight into the bank works normal, but I had to convert it to the format of the Larable. It runs, but returns no results. Where am I wrong? It seems that…
-
1
votes0
answers436
viewsError adding Constraint (General error 1215) - Orange
I am trying to create two related tables. When trying to 'migrate' them, the error is returned: "SQLSTATE[HY000]: General error: 1215 Cannot add Foreign key Constraint (SQL: alter table 'Companies'…
-
1
votes1
answer136
viewsRedirect fault Laravel
Expensive, Can you help me with this portable redirect? I created a method where it re-evaluates the data and redirects, on the other hand when redirecting I get the Route error…
laravel laravel-5 laravel-eloquent laravel-blade redirectasked 6 years, 2 months ago Ronaldo Adriano 61 -
1
votes1
answer199
viewsLaravel Relationship on Datatable server side
Would you have some way to pass the model relationship to the columns of the Datatable server side? For example in the Datatable script: columns: [ { data: 'marca_id', name: 'marca_id' }, { data:…
-
1
votes1
answer1557
viewsUndefined offset 0 - Laravel
I have a list of users, each user has their 'role' (role/function within the system, such as 'user' and 'admin') and this role has to be shown on the user listing screen, which I did using the code…
-
1
votes1
answer250
viewsUse of Foreign Keys Laravel 5.6
Good afternoon to you all. I created a Migration "clients" in the Newsletter that receives 3 foreign keys from the entities: modalities, requests and locals. In my view when registering a client and…
-
1
votes1
answer2182
viewsCall to Undefined method Illuminate Database Query Builder::table()
I’m trying to popular a datatable, but I’m not getting any help. Could you help me? ============= Avaliativo_relatorio - Model ======== <?php namespace App; use…
-
1
votes1
answer133
viewsClause Where takes too long
I’m wearing the Laravel 5.6 My model is normal <?php namespace App; use Illuminate\Database\Eloquent\Model; class MyTable extends Model { protected $table = 'myTable'; public $timestamps = false;…
-
1
votes1
answer6293
viewsUpdate a single information in Laravel
I’m starting work with Laravel and I was wondering if you could help me. I need to update a single value in the bank, using 'name' in the Where clause instead of id. This is for a real system…
-
1
votes1
answer115
viewsI can’t make research work with eloquent and relationship!!! Laravel 5.5 and mysql
I’m doing a search taking a piece of word and playing a search like LIKE for fields fields. Use the Eloquent and relationships, but does not bring the data. { $pesquisa = $dataForm['pesquisa'];…
-
1
votes1
answer47
viewsUPDATE VIA CSV LARAVEL
I have this parameter to import data via CSV and I want to know how to create the UPDATE function based on the CODE field. public function importEstoque(Request $request) { $validator =…
-
1
votes1
answer208
viewsAccessing attributes from multiple different relationships in a CRUD Eloquent Laravel 5.7
Guys I have a structure like this model (Modelo apenas ilustrativo) and want to know how I can access the data of the whole relationship to make a insert/update in these tables with the data…
-
1
votes1
answer263
viewsQuery "or" and "and" in Laravel
Could someone help me? I need to do this query on the Laravel: SELECT * FROM materiais where material like '%caneta%' or localização like '%armario%' or fornecedor like '%kalunga%' and setor =…
-
1
votes1
answer205
viewsIntermediate relationship between two Laravel tables
Good evening I have the following tables in my application. Doacao -id -nome -doador_id Instituicao -id -nome Doador -id -nome I need to carry out the relationship, in a third table among the…
-
1
votes1
answer124
viewsLaravel - Inserting & Updating Related Models
in the Laravel documentation it teaches how to do Insert on related models. Here is an example of how to do it in the documentation: Inserting & Updating Related Models $comment = new…
-
1
votes0
answers45
viewsHow to make relationship using the result of a relationship with Eloquent
I’m having trouble making the relationship between the table produtos, opções and tipos de opções on Laravel, I can bring the products and their options using Product::with('options')->get(), but…
-
1
votes0
answers32
viewsProblem in the logic of a tab system with relationship between tables
Personal I have two tables that relate to each other. Are they: Category: public function up() { Schema::create('categories', function (Blueprint $table) { $table->increments('id');…
-
1
votes1
answer450
viewsHow to do a like research in Aravel 5.5 using eloquent relationship?
I need to do a survey using like in a model that has relationship with another table(equipment). What has happened is that it is bringing all the records of the ordemservic table with the null…
-
1
votes2
answers199
viewsRelation Hasmanythrough returns empty Eloquent
I am developing a sale screen and on this screen it is possible to select several products that belong to the table produtos, the structure of the tables is as follows:: vendas: - id produtos: - id…
-
1
votes1
answer1073
viewsSlim Framework 4 with Eloquent ORM
I am using the Slim-Framework in version 4 for api creation and would like to use together Eloquent to facilitate manipulation with the database. But I couldn’t find any material/example of how to…
-
1
votes1
answer83
viewsMigration in more than one bank
I need to turn the remote php artisan migrate and each Migration go to your respective database, I have the following code on .env: DB_CONNECTION=mysql DB_HOST=163.25.138.18 DB_PORT=3306…
-
1
votes1
answer244
viewsInner Join Laravel - Erro Where clause is ambiguous (23000)
I am learning how to use Framwork Laravel and I came across the following error to perform an Join Ner (remembering that I already have a database with information so I am not used Migrations)…
-
1
votes1
answer121
viewsHow to perform a consultation in the bank applying "exceptions" with a relationship?
I need to get all users with "Exceção" those of the function containing the id=2, it is possible? You can fit a Where in that consultation? I have the following consult at the bank Laravel which…
-
1
votes1
answer125
viewsDoubt between relationships with Laravel and Eloquent
I have the following model, using Laravel 5.8 I ran all the records and structured the relationships. On my Dashboard I need to list in card form all reports from a specific user. How could I do…
-
1
votes1
answer58
viewsError while running Migration
Error: 1005 Can’t create table 'cobranca_simples. #sql-f04_1f0' (Errno: 150) (SQL: alter table carteira_cliente add Constraint carteira_cliente_carteira_id_foreign Foreign key (carteira_id)…
-
1
votes1
answer402
viewsLaravel - Eloquent Many to Many
I have this structure Migration from the Exercise table public function up() { Schema::create('exercicio', function(Blueprint $table) { $table->increments('id');…
-
1
votes1
answer33
viewsLaravel. How to use request to perform APP search
Good morning gentlemen I am starting my studies in Latin working with version 6 of the framework, and I came across problem that is probably a detail that I missed in my code. When trying to perform…
-
1
votes0
answers82
viewsMysql usage with Laravel and table items records are disappearing what might be?
I have a mysql 5.7.29 database called "base_default" with collation and encoding according to the image below and the api uses Laravel 5.6. on this basis I have the following table structure: data…
-
1
votes1
answer66
viewsDisplay the input id data?
I have the method responsible for calling a page (View) which displays the data referring to the last id entered in the database and I am using the framework Laravel and ORM Eloquent public function…
-
1
votes2
answers81
viewsAdd data from "pivot" table of relation Many to Many
I have 3 tables (clientes,seguradoras e clientes_seguradoras) that relate through 2 Models (Cliente e Seguradora) in Laravel Each customer can have several insurers, and for each insurer he can add…
-
1
votes0
answers49
viewsInsertion of encrypted and related data into Laravel 7 database
Save, I need help. I am developing a system that has a user table and a table of enrollments. The registration data is related to the CPF registered in the Users table. The problem is that now I…
-
1
votes0
answers172
viewsSyntax error or access Violation: 1066 Not Unique table/alias with polymorphic relationship in Laravel
I’ve been racking my brain for weeks and I can’t solve this problem. I’m using this package https://github.com/rappasoft/laravel-livewire-tables to use Datables in Laravel with Livewire. I have…
-
1
votes0
answers24
viewsSort object listing by relation Many-to-Many
OBJECTIVE: To order a list of eloquent entities based on a column of a Many-to-Many relationship. To create a system of favorite posts, I created a favorite_posts table that would be the link…