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
-
3
votes1
answer867
viewsHow to filter time in a datime field in eloquent?
How can I compare if a time is equal to a time stored in a column datetime using the Eloquent?
-
3
votes2
answers451
viewsEloquent save() method does not work
When I try to use the method save() eloquent-Variable 5.1, in the manner requesting the documentation, the update is not made in the bank. This is how you ask for documentation: $flight =…
-
3
votes1
answer2086
viewsHow to create functions available globally in the Standard?
I would like to create functions that are globally available to reuse the code. What would be the best way to do this, in the Standard... The flow I need would be like this.: I’ll get a requisition…
laravel laravel-5 laravel-eloquent laravel-5.3 laravel-bladeasked 5 years, 10 months ago Sidiclei F. Almeida 307 -
3
votes1
answer4474
viewsMany Relationship for Many
Well I tried to read the documentation and develop this relationship but could not, actually I need to inform what is the name of the type of user. The database model is thus : MODELS involved…
-
3
votes1
answer282
viewsMigrations Laravel 5.4
I’m having trouble trying to run my Migrations, when I run: php Artisan migrate:refresh --Seed Error occurs below: [Illuminate\Database\QueryException] SQLSTATE[23000]: Integrity constraint…
-
3
votes2
answers874
viewsSelect specific columns from two related tables
I have an N x 1 relationship, 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…
-
3
votes1
answer5901
viewsGeneral error: 1215 Cannot add Foreign key Constraint
I am trying to add a foreign key to this table with the following code block public function up() { Schema::create('registros', function (Blueprint $table) { $table->increments('id');…
-
3
votes3
answers459
viewsHow to make two WHERE clauses inside a nested WITH
I have the following code snippet $sectors = Sector::where('company_id', $id) ->where('status', '0') ->with('charges.levels') ->get(); and need 3 conditions Status of sector be it 0 Status…
-
3
votes2
answers290
viewsDoubt when performing SQL with Eloquent of Laravel
I’m with a bug I don’t know why. I have in my controller the following Eloquent: $balances = BankUser::select(DB::raw('SUM(balance) AS total, created_at, DATE(created_at) AS total_at'))…
-
3
votes1
answer130
viewsWhere do Eloqent Laravel Doesn’t Work
I have the following code public function getConsultaLocacao() { $consulta = LocacaoBanco::where('id',4)->get(); foreach($consulta as $v) { echo"aqui->".$v->datalocacao; } echo…
-
3
votes2
answers280
viewsHow to write this query using Eloquent?
I need to write a specific SQL in a project Laravel but I can’t convert the SQL for the syntax of Eloquent, basically, I need to do this SELECT: SELECT * FROM `movimentacoes` WHERE nome LIKE…
-
3
votes1
answer630
viewsHow to get hasMany relationship data
I have a table Grupo and a Topicos, where the group has many topics and this is my code: public function topicos() { return $this->hasMany('App\Topico'); } In my Controller is like this: public…
-
2
votes1
answer3313
viewsHow to do a search with multiple filters as a parameter in the Laravel?
I’m having a question about how to do a customer search with multiple filters. Example: nome cliente, tipo de cliente, status do cliente, endereço, cidade. Detail: all these filters are in different…
-
2
votes2
answers522
viewsRecovering value in the pivot table as property of a relationship part
I have the relationship manyToMany amid Grupos and Usuarios and a pivot table grupo_usuario which stores the keys and an extra field aprovador, boolean, which serves to indicate whether the user in…
-
2
votes1
answer5625
viewsCreating Foreign Keys by Migration - Laravel
I’m having trouble when I try to create foreign keys by Migration in Laravel. Watch my Migration!!! <?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint;…
-
2
votes2
answers1415
viewsLaravel - Update all fields from a large table
I have the following problem... I am migrating a system, and in the same I own a client table This table has a field called "cli_password", in which the customer’s password To use Laravel…
-
2
votes1
answer281
viewsHow to make Inner Join inside the Auth in Laravel 5.3
In the Migration standard that Laravel brings to use the Auth, made a Foreignkey with another table linking by ID. For better understanding put here the tables and with the following columns: Plants…
-
2
votes1
answer1294
viewsHow to bring only the latest records with Laravel 5.2
I need to return the last 10 records to a view.. return view('home.home', [ 'data' => $this->sale->get(), //aqui eu quero pegar os 10 últimos 'nav' => 'dashboard' ]); There’s some…
-
2
votes3
answers445
viewsHow to make the relationship of an extra field (pivot) in belongsToMany
Currently I have the following situation: 1 User can belong to several municipalities Within that relationship - municipios_usuarios - I also need to save who made this relationship, ie usuario_id…
-
2
votes1
answer781
viewsLaravel 5 improve filter
I created a filter in my view index, when I put something inside one of the filter inputs enters ifs but I think it’s not good this way, someone knows somehow better? public function index() {…
-
2
votes1
answer236
viewsPicking up monthly items ELOQUENT MODEL
Well I need to make one query where I have to bring all the listed items of the month in which we are. In the query I’ve done I’m bringing them all with status O of OK: $vendas =…
-
2
votes2
answers2912
viewsWrite to two different tables using the same View
I am registering suppliers, and I need to record it in a table and your address in another. I use a single view suppliers. to fill in all the data. How can I separate this data to save it to their…
-
2
votes1
answer722
viewsLaravel - How to call a different action from store,update, Edit?
I created a action without being the standard of resource, how can I call the same for an action on form as I call the update and store. <form method="POST" role="form"…
-
2
votes1
answer62
viewsLaravel Queries SQL Doubt?
I’m starting with the SQL of Laravel I searched much more I did not get an answer on how to make a AND after a where, follows example code to implement a AND. SQL: UPDATE contas SET valor_titulo =…
-
2
votes1
answer463
viewsOptimize queries with leftJoin Laravel?
I have linked tables and when I need to access the information I recreate the query: DB::table('paciente AS pac') ->leftJoin('pessoa AS p', 'p.id', '=', 'pac.id_pessoa') ->select('p.nome,…
-
2
votes1
answer364
viewsHow to change the default name of an eloquent column
I am on a project that is in production, and by default when we use a foreign key in eloquent we follow the following "user_id" rule for example to store user id. Only at the bank I’m working they…
-
2
votes1
answer46
viewsLarval Relationsships 5.4
I have 3 tables,[Users -> Departments -> Posts] where the Users table has many Departments that Departments has many Posts. My question is: How do I relate the 3 tables to the with() method…
-
2
votes1
answer97
viewsUsing Whereraw with Datediff
I need to take the difference in days between the current date and the date stored in the bank, subtract this difference by 90 and then check if the result is equal to 7. Where is the error?…
laravel-eloquentasked 7 years ago Diego Vieira 1,807 -
2
votes1
answer312
viewsChange column names used to save timestamp
When I store or edit data in a table by Larable this creates a timestamp using the fields created_at and updated_at But I have to store the data in a table shared with another system, and this uses…
-
2
votes1
answer259
viewsToo Loud for Too Many?
I have this model public function exercicio() { return $this->belongsToMany(Exercicio::class); } and public function treino() { return $this->belongsToMany(Treino::class); } My Controller…
-
2
votes1
answer407
viewsMulti-table heritage in Laravel
I have an entity Resource, which in turn has several implementations, for example, VideoResource and MarkdownResource. Resource has several properties shared, the other two examples in turn have…
-
2
votes1
answer644
viewsHow to get the result of the query executed in Eloquent?
How do I get the result of query which will be executed in the database? Example: foreach ($prestadores as $prestador){ $achou = \DB::table('modulo_pr_espelho') ->where('prestador_id','=',…
-
2
votes1
answer363
viewsProblem with wherein Eloquent Laravel
I need to execute a query with the parameters as below: $questoes = Questao::leftJoin('capitulos_questoes', 'capitulos_questoes.questoes_id', '=', 'questoes.id') ->leftJoin('modulos_questoes',…
-
2
votes1
answer484
viewsUploading image to server does not work
When I upload locally, using WAMP64, everything happens normally. However, when I upload by the site, which is on the production server, the following error message is displayed. Nowritableexception…
-
2
votes2
answers98
viewsHow to relate two records in an elegant way?
At a certain point of my application I am creating a post and relating this to the session user: public function adicionar(CadEditPost $request) { $request->merge(['user_id' =>…
-
2
votes2
answers1025
viewsSum with SUM()
Two days ago I’m banging head with a query in the database marrying tables and returning the sum of values, I can perform the query by the quiet Phpmyadmin. Follows the query that works on…
-
2
votes1
answer584
viewsSelf-relationship with Eloquent in Laravel 5:3
I am building an immigrant control application and I own an imigrants table that has 3 self relationships. Its structure is as follows. id -> pk first_name -> varchar last_name -> varchar…
-
2
votes1
answer56
viewstrashed() returning 'true' after Store()?
I have a model Manifestation using SoftDeletingTrait to keep them inactive in the bank and in the ManifestationController I have the following method destroy(): $manifestation =…
-
2
votes1
answer345
viewsHow to return relegated records between Laravel tables
I have 2 tables city and state I own the state and would like to know how to return all the cities related to the state Parana simply without having to do a loop Type $estados = App/Estado::all();…
-
2
votes1
answer54
viewsInfinite relationship...?
I have a question that would be, how to accomplish a relationship that can be infinite.: Ex: User table with the user id field that would be one for many with Post Table. Inside the Post Table would…
-
2
votes1
answer6457
viewsClass not found Laravel
Good afternoon, I’m starting with my studies in Laravel, the moment I entered the Eloquent ORM I started having problems. This is my controller <?php namespace App\Http\Controllers; use…
-
2
votes1
answer1277
viewsJoin no Eloquent - Join no Eloquent?
I’m learning Laravel now, and out of curiosity I came across the following problem, performing a Join between two tables, in my case, "categorias" and "subcategorias", when I will list the…
-
2
votes1
answer323
viewsError auth Lockable with another model?
People changed the name of the standard model of Laravel User.php for Colaboradores.php (of course, I set the $table and the $primaryKey model), I also changed the config/auth.php to model. but…
-
2
votes3
answers480
viewsHow do I know and count the number of rows in an SQL query with Laravel?
$teste = DB::table("cnaes") ->select("id") ->where("cnpj", $cnpj) ->where("cnae", $cnae); How can I know how many lines were affected by this query?…
-
2
votes1
answer475
viewsAdvanced search in Laravel 5
I’m starting to Laravel 5 and as an apprenticeship I am creating a simple employee registration. What I need is to recover from the bank a relationship of employees with exams based on search…
-
2
votes1
answer132
viewsI’m having trouble ordering the birthday boys of the month on Eloquent of Laravel 5.7
My query returns the birthday boys correctly, but when sorting by table column it sorts by year and by day. This is my query $birthday = \App\Admin\Clients::whereMonth('birthday',…
-
2
votes1
answer11610
viewsWherein no Eloquent
I’m trying to implement a query with the use of whereIn in Eloquent, but always generates a mistake, someone would know to give me guidance on? My code is like this: $result =…
-
2
votes1
answer2431
viewsSelect with Laravel/Eloquent
I have the following select in my controller: $turmaAlunos = DB::select(' SELECT alunos.ST_ALUNO_ALU, alunos.ID_ALUNO_ALU FROM alunos WHERE alunos.ID_ALUNO_ALU NOT IN ( SELECT…
-
2
votes1
answer165
viewsLaravel - Relationship Manytomany Extra Columns
I have the following scenario in a database: Tables: User id, name email Enterprise id name User company id_usuario id_empresa start date end date In this scenario, I need to bring the information…
-
2
votes1
answer26
viewsLarval Relationsships 5.4 accessing search data with?
I have a relationship of One To Many, wanted to know how to access data from the two tables. Behold: Album::with('imagemAlbums')->where('departamento_id', $id)->get(); Return of dd() now in my…