Questions tagged [eloquent]

Eloquent is Laravel's own object-relational mapper. It is named "Eloquent" because it allows you to work with your database objects and relationships using an eloquent and expressive syntax.

3
votes
1answer
27 views

Insert statements working when inserting emojis, but throws error when using eloquent

Running the query, INSERT INTO table (ref_id, user_id, role_id, text) VALUES (233, 3, 40, 'Hdhdhdh😜😀😊😃hzhzhzzhjzj 我爱你 ❌') works just fine in Sequel Pro, but when using eloquent, it throws an ...
1
vote
0answers
26 views

Need to change timezone dynamically for existing project

There is existing project only for one country. Bur for now, it should be used for multiple countries. So I need some common place to change timezones. I decided to update & insert in only London/...
0
votes
0answers
20 views

LARAVEL - eloquent get relation with null ids

I am working on some eloquent query. So the idea is that I have 2 models, let's call it Files and Pricing. Files hasMany so in pricings table I have file_id field. But I have default prices in ...
0
votes
1answer
27 views

How to display user name instead of id (foreign key) in laravel & vue.js

I want to display the user name instead supervisor_id in the table list in Vue.js. this is one to many relationship. supervisor_id is foreign key from user table. /// this is view in vue.js. I want ...
0
votes
0answers
13 views

how to implement task completion in limited time for different timezones like 10 am till 11 am

I have an Laravel app that has a time limitation for task completion, like 10 am till 11 am. Users should be able to complete their tasks in their local time. so out of the time limit boundaries they ...
-1
votes
1answer
35 views

How can I define the inverse polymorphic many-to-may relationship in eloquent?

I'm new to Laravel here. Some confusion regarding eloquent relationship. I'm trying to achieve this : Relationship Here's the ER-Diagram 1 Question can be any type (multiple-choices/ordering/...
0
votes
5answers
37 views

Check how many queries are sent to DB while viewing a Blade in Laravel

I have a collection. $items = Item:where('count' , '>' , 5)->get(); And I have an array of ids. $ids = [2 , 4 , 7 , 8]; In my Laravel blade, I want to show each on $items based on ids array. ...
0
votes
5answers
33 views

How to output table data from controller to view?

I'm in the beginning stages of trying to make sense of Laravel and am having trouble displaying the 'illuminate collection object' passed to a blade from a controller. My print_r is outputting "...
0
votes
1answer
29 views

Laravel 5.8 custom timestamp column names not working as documented

Nevermind, I'm a giant idiot. I had two copies of the model. I had modified one of the models to include the CREATED_AT/UPDATED_AT constants, but in my controller I was calling the other model. I ...
0
votes
1answer
22 views

Call to undefined relationship in Eloquent, Laravel 5.7

I am four hours in this. I just cannot see the problem. I using Postgres not Mysql. class ValorVariacao public $table = 'valores_variacoes'; protected function tipoVariacao() { ...
0
votes
1answer
24 views

Cannot do any queries on BLOB and CLOB columns (DB2/PHP/Laravel/Eloquent)

I am currently working on a simple CRUD application for work and have come across an issue with BLOBs and CLOBs. I am unable to do any queries with any column of this type. I am not allowed to drop, ...
0
votes
4answers
44 views

How to retrieve a field from a dependent table from Users trough the class Auth:: in Laravel 5.8?

I have the follow relationship where users to professionals is one to many: I would like to retrieve the image_path from professionals when a authorized user get access to the page. This is what I ...
0
votes
1answer
23 views

how to add condition when i use unique function in validation in laravel framwork

I have two databases; the first database contains a table called product which contains id, status, deleted. The second database contains a table called product which contains id, id_product, name, ...
1
vote
1answer
21 views

if condition is true show block button else condition false show unblock button : Laravel, Javascript

If $block->user_username data empty show block button else run another if and else condition. But In foreach loop else not working @else <a href="#0" class="cd-popup-trigger">Block2</a> ...
0
votes
0answers
24 views

Laravel Eloquent query relationship next 1 item

What is the cleanest way for me to query the next 1 item in a laravel relationship? I have 2 models, Users and actions (1 user has many actions). Actions have to have a date, so when someone ...
1
vote
0answers
32 views

Eloquent With A One to One 'Like' Relationship

I currently have an Eloquent Model that I have tried to simplify for this example and has a similar structure to the below. class Student extends Model { public function classes() { ...
0
votes
2answers
26 views

Returning an empty JSON object when a nullable column value is null within an eloquent query scope

I have the following query scope that will return keys (JSON) that may be stored inside a container: public function scopeKeys($query, $container) { return $query->select('keys') ->...
0
votes
3answers
36 views

How to comma separate properties from a Laravel returned object

First, my apologies if the issue has been resolved. I read a lot of similar posts, but not quite the right one for my case. I am setting up a simple project in Laravel 5.8. I want to create a simple ...
1
vote
2answers
33 views

LEAST and GREATEST date value from multiple tables, laravel way

Is there any "Laravel-ish" way to capture the earliest and latest dates from multiple date fields in several laravel tables? table for model1: fielda| fieldb| date1 table2 for model2: fieldc| ...
0
votes
0answers
41 views

SOLID (SRP) vs performance

I'm trying to improve my code by applying SOLID principles and I don't know what to prioritize, SRP or performance. The problem involves fetching data from two different sources and then persisting ...
0
votes
1answer
26 views

how to retrieve multiple images from database laravel?

I want to retrieve multiple images of single user..? anybody pls help me. Controller: public function fetch(){ $id = Auth::user()->id; $ads = Ads::where('user_id', $id)->with('images'...
0
votes
1answer
22 views

How to write mysql join sub query from 5 tables in laravel controller

I have a MySQL query like bellow, and I want to use it in laravel controller, I know how to use join in laravel, but I don't know how to write it when we have another sub query in the join statement,...
-4
votes
0answers
40 views

How to convert this mySQL script to Eloquent

Hi I'm trying to convert a MySQL query into Eloquent in Laravel 5.5, The query that i have in place to filter all the templates is the following: $tableData = Template::leftJoin('form_templates', ...
-1
votes
0answers
30 views

How can I calculate Average Time from all columns in database

How can I calculate Average Time from all columns in database.I am fetching all records for particular column. So, I used foreach but then It is considering single value only. Can you please suggest ...
0
votes
1answer
34 views

Laravel 5 add attribute to User model before login

I need to add a custom attribute to the User model when the user logs in. This value is not in the database so needs to be added after. The attribute I need to add is called client_id I've search ...
0
votes
0answers
24 views

How can i filter and paginate with two date fields in laravel?

I'm trying to make a filter with an two date select in laravel and it works but when i try to access to the second page of the filter i got an 404 error. I have been trying to filter using two fields ...
-2
votes
0answers
12 views

what is the best way to retrieve the blocked account using elequent?

how to retrieve the names of the users I've blocked using eloquent not query builder the models are Users,BlockedUsers in this enttey there is user_id, blockedUserID, and its one to many , public ...
0
votes
3answers
15 views

Same Foreing Key Twice That Refers to One Model

I need to make an advice platform for products. User can make advices under product section. So product has many advices. Also advices belongsTo product. But on product_advices table i have product_id ...
0
votes
1answer
28 views

Utilizing the belongsTo eloquent relationship with a slug and not the relationship id

Given the following two tables and relationships: Model Containers: id, name, desc, created_at, updated_at public function items() { return $this->hasMany('App\Models\Items', 'container_id', '...
0
votes
1answer
31 views

performance of whereBetween method

please explain : what is difference in performance , when we use whereBetween("col",[value1,value2]) or where("col",">=",value1)->where("col","<=",value2) in large data ? actually ...
0
votes
3answers
61 views

How can I decrypt password to login in laravel?

While changing the password I am using this function public function passwordChange(Request $request, $userId) { $user = User::find($userId); $user->password = Crypt::encrypt(...
0
votes
1answer
30 views

Ignore accent in multiple search request

I would like to know how can I ignore the accent in multiple search with eloquent from Laravel. Currently I have this : // $searchTerms => 'Héllo human'; $explodedTerms = explode(" ", $...
0
votes
0answers
32 views

How to belongsToMany two keys and one via another relation

sql scheme: users id (ai) bulletins id (ai) owner = user.id conversations id (ai) owner_id = user.id //UPDATED bulletin_id = bulletins.id // this I can't get user ID(this is another 2nd user!) - ...
-2
votes
0answers
36 views

i want create relation between four table in laravel 5.8 is it possible

I have four table and I want relation between them structure are follow product table id site_id name description status image sites table id name description zone table id name description ...
0
votes
2answers
26 views

“Missing required parameters for [Route: property.edit]” error when editing product

I am trying to edit a product, but my route is not working. Please let me know how to get this resource route working. This is my web file: Route::resource('product', 'ProductController')->except(...
0
votes
1answer
36 views

Only display selected fields to the view using Laravel Query Builder

I have quotes I am displaying to the screen one at a time upon each page refresh. The data is displaying fine from the DB; the issue is that I am getting the (id) display on the screen as well when I ...
0
votes
1answer
55 views

Laravel Eloquent filter product's attributes

I am making a filter function for products. I have 2 models: Product and Attribute (BelongsToMany relationship) Attributes table: id name ------------- 1 RAM 2 HDD Products table: ...
1
vote
2answers
32 views

Laravel 5.4 - multiple relations in few tables

In a picture below we can see relations between my tables. My target is to get "type" from driver_license_types. Starting at user object. For example: $user = User::find(1); and from there I need to ...
0
votes
1answer
30 views

how do i pass data value to another page via link in laravel?

i am trying to make a list of locations that you can rent. but to rent the place you need to fill in some information. to fill in this information you excess another page. how do i make it so laravel ...
0
votes
1answer
28 views

orWhereHas cancelling out my other Where condition

So I am trying to do a query that is filtered by a date range. The issue is I need to do a orWhereHas query as well which currently is not obeying the my whereBetween query. So I have 2 tables Promos ...
2
votes
2answers
27 views

Eloquent efficiency for composing links in a rest api

We are doing a learning exercise with Laravel 5.8 and Eloquent for developing a version of a REST api. The database tables (company, contact & note) are rather simple in terms of their ...
-1
votes
1answer
21 views

How to create table and design relationship for this article

I have tour service on my app, each tour has many "required documents", "rules", "services" and ..., how do i create a table to connect each tour to it's own options!? by the way i don't want to ...
0
votes
2answers
33 views

Laravel - How to query a relationship on a pivot table

My Setup I have a many-to-many relationship setup and working with my database. This is using a pivot table that has an extra column named "linked_by". The idea of this is that I can track the user ...
0
votes
1answer
38 views

Laravel 5 - calling create() on hasMany relationship with conditions

I have a couple of models - let's call them Item and Ean. In Item model there are a couple of hasMany relations to the Ean model. public function eans() { return $this->hasMany(Ean::class)-&...
1
vote
2answers
32 views

When I build an Eloquent relationship it makes problem here I show my code I use tinker to see relation but it doesn't build

When I build an Eloquent relationship it makes problem here I show my code I use tinker to see relation but it doesn't build pass.php <?php namespace App; use Illuminate\Database\Eloquent\Model;...
2
votes
0answers
56 views

Using chunk with relationships models query

I'm trying to query a lot of rows with two models in a controller, when i increase the number of days i get 500 error I'm getting memory leakage and 500 response as result. This is using laravel 5.8 ...
1
vote
2answers
25 views

Get list of submitted fees along with date from fees table using student_id as foreign key

I have a students table and fees table. students -------------- |id | name | -------------- fees --------------------------------------------------------- | id| student_id | paid_fees | ...
0
votes
2answers
37 views

Database sql server with results but view is empty

something really strange is happening. So I have a table named Lactinfo_News with 1 row. I've created also a view called LACTINFO_VW_LatestNews which have "SELECT * FROM Lactinfo_News" and is ...
1
vote
1answer
36 views

How can I pass a previously declared DB::raw() column into a whereRaw() query

I have a laravel eloquent query that gets a users ID, and their distance from your own position $lat = Auth::user()->lat; $lon = Auth::user()->lon; $users = DB::table('users') ->select(...
0
votes
2answers
71 views

Eager load for collections on the fly

I have this, user has many to many property via pivot property_users. I am making somehow reusable classes in my webapp. These are the models with their eager loading functions: //User model public ...