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
-
0
votes0
answers452
viewsGroup by month or week with Laravel eloquent
I have a project that has managed my investments, that is, it takes my daily statement and saved in my project so that I can see how much it is yielding, in short I have a table that are daily these…
-
0
votes1
answer447
viewsEloquent Relationship / Laravel Onetomany
Good afternoon, I am using Laravel 5.7 to create an order system. Therefore I have 3 tables: customers, products and orders. My Database: For now my Migrations are like this: Migrations: Migration…
-
0
votes1
answer180
viewsIntegrity Constraint Violation in "Many to Many" create - Laravel
Context: When registering a company, by being "attached" several customers to it and that same customer can be "attached" in other companies. I have the following database structure: Model "Client":…
-
0
votes0
answers49
viewsDoubt about eloquent with Laravel
Eai guys, I’m setting up a management system of football clubs just to practice and in that came a question, I have the following eloquent: $matches = DB::table('ut_tickets AS TIC')…
-
0
votes2
answers122
viewsLaravel query two tables, not showing if id are equal
I have two related tables in the database: Students and student_schedules. At some point, I want to list all the Students that NAY are in student_schedules. I tried to do it like this, but it didn’t…
-
0
votes1
answer535
viewsSearch records between two dates using the eloquent of the Standard
I need to search the bank records between two dates. example: $emprestimos_material_qtd = MultimeiosDetalheEmprestimo:: where('recursoId', 2) ->where('dataDevolucao', null)…
-
0
votes1
answer309
viewsRelate two tables through another
I have 3 tables, processos, empresas and processos_empresas. table structure: processos: - id empresas: - id - nome_empresa processos_empresas: - processo_id - empresa_id Brief explanation of how…
-
0
votes1
answer23
viewsError searching for Description in another related table
Error: Trying to get property of non-object View @foreach ($titulos as $titulo) <tr> <td>{{ $titulo->id }}</td> <td>{{ $titulo->titulo_tipos->description…
-
0
votes1
answer75
viewsFunction does not work within class [Laravel]
I’m trying to call one function inside another in one of the controllers of my Laravel project, but when the flame the page is all blank and presents no error. public function index() {…
-
0
votes1
answer177
viewsData were not changed in the database - Standard 5.7 eloquent
Good afternoon guys, I’m trying to do an update but the values entered in the fields not saved in the database, follow files to check. Index.blade.php @extends('layouts.app') @section('content')…
-
0
votes1
answer123
viewsProblem with JOIN in Laravel
I have a little problem when performing a Join. Basically I had made this code and it was working, but I had the need to change the primary key of the table 'products' to 'code'. After that, even…
-
0
votes2
answers74
viewsArtisan Command - Foreach Laravel - Count affected lines
I created a command in Laravel to run at a certain time and now I need to get the result only of the affected lines. The method I used makes a count of the entire loop. $count = 0; foreach…
-
0
votes1
answer505
viewsHow can I list 3 tables using Laravel
Hello, I need some help with Relationships. I’m studying Laravel and I came across this problem. I could use Join, but wanted a simpler way and use Laravel’s relationships to do this kind of search.…
-
0
votes1
answer301
viewsLaravel - how to save if there is a change in the model
Good afternoon guys, I have a problem which is as follows would like to know if Laravel has any method to check if any changes were made before saving the model Example. table users, if the user…
-
0
votes1
answer30
viewsHow to validate Insert with relationship
I have three tables, one of the types of vehicles: car, motorcycle. A table of brands: Honda, Ferrari Another associative, called tag_type_vehicle. The Honda brand for example, has cars and…
-
0
votes1
answer55
viewsQuery using Eloquent multiple fields
all right? I would like a help from you to put together a more "elegant" consultation at Laravel. I currently have the following scenario. I need to check if a client is already registered in my…
-
0
votes1
answer92
viewsTernary Laravel Relationship
I’m creating a polling system where I have the following tables. A poll has several options. An option belongs only to a poll. A user can vote in multiple polls, but one option per poll. Soon I made…
-
0
votes1
answer387
viewsProblems with table linkage in the Standard
When I type php artisan migrate it generates this error: Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table `blog`.`produtos` (errno: 150 "Foreign key…
-
0
votes1
answer45
viewsQuery SQL returns data that was not to be returned
Well, I’m putting together a ticket sales system for football matches as a project of my course I’m working with the Laravel + Eloquent ORM, but I’m having an inconsistency. My code is: $matches =…
-
0
votes1
answer25
views"Unexpected data found" on function return
I have a function that should return a json from a Collection generated by a Builder query. $today = Carbon::today()->format('Y-m-d'); $tasks = Task::where('date',…
-
0
votes0
answers23
viewsBonus for better performance in massively updated records search using a secondary table with Laravel
I am using the Laravel framework in a project and in it there is the model Product. On this system, I also have an API where one of the endpoints gets a date and should return the changed or removed…
-
0
votes2
answers110
viewsHow to update a table with an array in the Laravel?
CONTROLLER CODE $form_data = array( 'numdoc' => $request->numdoc, 'data_emissao' => $date_emissao, 'data_debito' => $date_debito, 'cliente_id' => $request->cliente_id, 'devedor_id'…
-
0
votes1
answer99
viewsLaravel - Query with 3 tables (1-N)
I’m trying to relate these tables: The goal is to show: Nome,Descrição,Parcela,Valor Model Cliente: class Cliente extends Model { public function recebtos() { return…
-
0
votes2
answers242
viewsHow to instantiate one model inside the other in the view?
Error: Property [id] does not exist on this Collection instance. MIGRATION DIVIDE <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use…
-
0
votes1
answer178
viewsMigrations Laravel 5.8
A mistake is happening when I’m going to make Migration one for many. The goal is to make a customer will have many phones and a phone will belong only to one customer. In the code below you can see…
-
0
votes2
answers78
viewsFactory of Relation N:N
I am with an application where users can see or not certain system module according to their permissions. These permissions are saved to the database in a way N:N and managed in UserPolicy, as an…
-
0
votes2
answers167
viewsEloquent: Relationship (JSON) -> Hasmany and Belongsto
Say guys all right? Next, I have a little problem related to two models within my project. First Model I have a relationship hasOne: <?php namespace App; use Illuminate\Database\Eloquent\Model;…
-
0
votes1
answer230
viewsFilter results using 3 tables in Laravel 5.8?
Create in controller a filter that takes data from 3 different tables. Below I put the relationship and an example of what needs to happen. I am not able to create in controller the filter that…
-
0
votes1
answer1055
viewsDelete data with regards Many to Many in Laravel
I’m having a problem deleting associated data in Laravel. I have user tables, records and tags. As you can see the table users connects with records, while a pivot table (registro_has_tags) connects…
-
0
votes1
answer137
viewsProblem with Route and IF in Laravel 5.8
I have a Route that passes 2 parameters, and can be optional. In the view, If you click on Link 1 (you pass the 2 id’s) I want you to check certain options. If you click on Link 2 (you will pass…
-
0
votes1
answer95
viewsLaravel - Where in relationships?
I have a function that looks for a value of a query with WHERE in relationship : $em = \App\Elevatoria::whereHas('elevatorias_monitoramento', function(Builder $query) {…
-
0
votes1
answer650
viewsConsultation with eloquent relationship
I am hitting myself here with a simple query on Laravel, I want to make a query on the client table and bring the customer’s address together. Note: Whenever I try it brings the address id and not…
-
0
votes0
answers32
viewsRelating Type and Subtype
What can I call a Subtipo searching for the tipo_id, I did some tests here but none successfully this is my first project. Table of the Type public $timestamps = true; protected $table = 'tipo';…
-
0
votes1
answer374
viewsValidation error in Laravel update
Follows the code: public function update(Request $request, Contact $contact) { $validator = Validator::make($request->all(), [ 'name' => 'required|min:6|max:255', 'email' =>…
-
0
votes1
answer91
viewsLaravel 7, use of Foreign key
Good morning, I am doing a small project in Laravel 7 and it is the first time that I use Foreign Key and relate two Database tables. In both Models of the respective tables I have already put a…
-
0
votes1
answer58
viewsLaravel when loading a relationship does not appear when returning as json
When trying to load a product’s images are not included when returning Model: class Product extends Model { public function images() { return $this->hasMany(ProductImage::class); } } Controller:…
-
0
votes1
answer54
viewsLeftjoin does not fetch id values - Laravel
I’m using leftJoin to bring data from 2 tables that are linked by a Belongstomany method to my index view. Virtually all data of the two tables appear when I give a dd in my variable, except the $id…
-
0
votes0
answers55
viewsLaravel save() returns true but does not change anything in the database
I’m trying to do an UPDATE to change my user’s password, the function is returning me SUCCESS, but when I go in the database nothing has changed. I am doing a post via Postman, for the following…
-
0
votes3
answers781
viewsHow to view the data of the last saved record in the database
how do I display in the view only the data of the last saved record in the database? I can display all the data by calling the All() method in the control, and the good old foreach in the view to…
-
0
votes1
answer45
viewsLaravel Eloquet AND-OR-AND Undefined variable
I have a function in the Repository to list only the employees not dismissed on a certain date use Parametergroup, but the condition does not find the $date parameter of the function, giving the…
-
0
votes0
answers65
viewsManytomany relationship between three tables
I have the following structure: Action -id -name -type Routes -id -name -controllers User -id -name -email -password -usergroup_id Usergroup -id -name -tenant_id I want to make a relationship where…
-
0
votes0
answers58
viewsHow can I optimize a consultation in Laravel?
I have several linked tables and when I do a query it returns all query: Model: class Apontamento extends Model { public function user() { return $this->hasOne(\App\User::class, 'id', 'user_id');…
-
0
votes1
answer38
viewsHow to show only the posts of the logged-in user?
I have a question at the moment of showing the post user only who is logged in? Man model: class propuestas extends Model { protected $fillable = ['titulo', 'descripcion', 'estado', 'linea_id',…
-
0
votes0
answers22
viewsCall relationship with WITH no Laravel with SUM()
Good morning, I’m having problems to call the next relationship in Aravel being that it has a Function that makes a sum() and group by and does not have the field of the relation one to one, after…
-
0
votes1
answer72
viewsFailed to parse time no eloquent
I have the following code: select('id','title', 'description', 'author', DB::raw("DATE_FORMAT(created_at,'%d/%m/%Y') AS created_at"))->get(); when I run it returns me the following error: erro":…
-
0
votes2
answers30
viewsGet default response if it does not exist in Laravel’s Wherein
I’m searching a series of items in a DB using Laravel through the function whereIn(). When returning, it presents a Collection with the information found, the problem happens when it does not find…
-
-1
votes1
answer531
viewsStore Laravel 5.7 date fields?
I’m not finding a solution to store only date, always required time. Error: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value
-
-1
votes1
answer17
viewsHow to generate dynamic urls
I’m working on a project for writers to publish poems and poetry. Urls will be separated by gender, for example: site.com/poems/field flowers/ However, I need to avoid double titles. Because of this…
-
-1
votes2
answers68
viewsCheck ID with a single foreach
I wonder if you have a certain id, without having to do two foreach @forelse($surveys as $survey) @forelse($survey->users as $user) @if($user->id == $auth()->user()) AÇÃO @empty @endfor…
-
-1
votes1
answer398
viewsAdd multidimensional array as an array item
I am working with Windows and I am implementing a permissions-based menu, I am recovering the menu data from a table in my database. I created a model and in it I am doing the logic to retrieve the…