kylemilloy kylemilloy
0
I have two models, a Risk and an Action. A risk has many actions and an action belongs to a risk. A risk can be "mitigated" when all of its actions (if it has an action count of larger than one) has a status of "completed". What I...
liquorfly liquorfly
4
Hey there! I'm pretty new to Laravel and might've overthought a solution to a question to which I hadn't found an answer yet. Database structure: videos - id - uploaded_at playlists - id - first_video_id playlist_video - playlist_id - v...
Hello everyone, I have no idea, how do this query with eloquent for get object. SELECT catalog.name AS name, MIN(catalog.sett_price) AS sett_price, MIN(catalog.pid) AS `pid`, catalog.title as title, catalog.description as description, catalog.cut...
itohin itohin
2
Hello! I need to use specific timezone in my app different from general app.timezone setting. This setting is also set in the config file 'timezone' => 'UTC', 'app_timezone' => 'Europe/Moscow' This is necessary in order for dates to be saved...
itohin replied
Solved
joshblevins joshblevins
1
Is it even possible to count this using eloquent. Table 1 (competency) Table 2 (Required User Level) Table 3 (Users) Relates to tb 2 one to many | Relates to tb 3 one to many I am trying to get a count of h...
rohit_mg replied
Solved
mrcorex mrcorex
6
Hey guys. I am trying to find a good solution to use illuminate/database (+ migrations) outside Laravel. I have the need of several packages (non-public) that are targeted for specific purposes. And they are going to be used in several projects, both...
nmeri17 nmeri17
8
There are model observers mapping to crud actions. Using them implies controller actions are not tightly coupled to authorization rules. I can create fresh endpoints that are authorized without explicitly applying gates to their handlers. Why would I...
channaveer channaveer
2
I have the following tables payments --------- id, user_id, payable_id, payable_type, status Payable can be of type User Subscriptions / Courses Registered and something else too course_categories --------------- id, name, slug courses ------- id,...
LaCoder LaCoder
1
Hello, I have applied softDelete in Bill model and File model as well. But when we use SQL join, it also gets deleted items that have deleted_at timestamp, $bills = Bill::where('is_bill', 1) ->join('files', 'files.bill_id', '=', 'bills...
andyandy andyandy
3
I want first 47 actors, that have highest "actor.subscription_id". (User hasOne Actor) orderBy('actor.subscription_id') doesn't work $users = User::with('actor', 'actor.data.actorOption', 'actor.subscription')->where('role_id', NULL)->...
palbandoz palbandoz
0
I've got a class that is related with itself: class Client { ... public function children() { return $this->hasMany(Client::class, 'idParent'); } public function parent() { return $this->belongsTo(Client::cla...
Abhimanev Abhimanev
4
Hi friends, i have an users table with already has last_login column. Now i want to add a new column as last_active. I want to set the default value of last_active equals to last_login. Here my migration public function up() { Schema::ta...
Thiago_LA Thiago_LA
3
I try to select column 'id' and 'name' this is my code: //Model/Category public function subcategories() { return $this->hasMany(SubCategory::class); } public function products() { return $this->hasMany(Product::class); } //Controller...
dani94 dani94
4
Hey guys! I would like to order my query by field date from two different tables. I have a Model Report with date. One report has (or not) one event with date. If a report has an event, the report date is null. So it only exists one date, or from rep...
dani94 replied
Solved
amitshahc amitshahc
7
There is Project->hasMany(Sites); Site->hasMany(issues); Issue->BelongsTo(Site) I want to create a relationship or scope in Issue Model where I can fetch the issues by project id. public function scopeByProject($query, $id) { ret...
forrestedw forrestedw
2
Hey, so I'm trying to do something like this: $categoriesWithASingleProduct = Category::whereHas('products') ->with(['products' => function (BelongsToMany $query) { $query->inRandomOrder()->with('media')->take(1);...
dani94 dani94
7
Hello guys, Im trying to create a scope with union two conditions. First condition: $query->whereYear('reports.date', $year)->whereMonth('reports.date', $month) Second: $query->join('events', 'reports.event_id', '=', 'events.id')...
ehsanquddusi ehsanquddusi
9
I need some help in converting this query into eloquent equivalent. The model in which the query is to be executed is named as Inventory. This field should be appended to the column list. What I am trying to achieve is, say, I already have columns a...
Nospoon Nospoon
5
I have two related entities, SimCard and Call, SimCard has many Calls. The Call entity has a total_length attribute. I need to grab top 10 SimCards, whose related Call records from the last month have the the highest average total_length. Is this pos...
Nospoon replied
Solved
asadali007 asadali007
2
Hello, everyone i am using ChunkById to update certain record but some error have come do you know what is the error how to solve this is my code /chunkById Flight::where('lastname', 'danel') ->chunkById(200, function ($fligh...
maltekiefer maltekiefer
1
Hello, I need you help guys. I have a table with the name addresses. Every entry has a delegatesid. But in a second table there are also addressesid and delegatesid. Theses second table is for the visibilities for delegates that not created the addre...
EdwinvanDessel EdwinvanDessel
0
Hi, I am working on an applicatioon that enables organisations to setup a subscription form for their event. Necessary functionality is that a participant can select multiple event parts (activities) of the event he/she wants to participante in. My s...
ehsanquddusi ehsanquddusi
2
I have two models, Advisory & User with a many to many relationship and one pivot table as advisory_table. I am trying to return latest Advisory for a User from this many to many relation. I have defined the relationship in User model as public f...
armingdev armingdev
5
Hello, Im looking for good way to make query with eager loader on relationship tables, but to take only columns that i need (select or pluck). $parts = Parts::with('cars', 'bikes', 'formulas')->get(); This work but it returns too much data from r...
asadali007 asadali007
4
the chunk method work in controller that example i show in below but how could i access chunk method in blade view files i tried many time but does not work .please if you know send me example that help for me //chunk method Flight::chu...
MarlonV MarlonV
0
Hi All, I've been fiddling with this for a while now, but I just can't get it to work properly. This mapping is neatly stored in the database. However, if the activities key is not present, the rest (campsite & remark) is not saved either. public...
jbolecke jbolecke
3
I use the 'encrypted' eloquent cast to encrypt and decrypt columns in a mysql database: https://laravel-news.com/eloquent-encrypted-casting Is there a way or a general rule to determine how big the size of the mysql column which contents gets encrypt...
Hi Laracasts community, Does any one knows why when i try to fetch a model with a User pivot table i get the following error... Call to undefined method App\Models\User::getProfilePhotoUrlAttribute() This is my query $this->notes = ProcessUpdate:...
Alfie replied
Solved
I have 3 tables "users", "companies" and the pivot table "company_user". For now a user has to a single company I have a relation in User model called companies() that is a "belongsToMany" this return a collect...
surendrasahi surendrasahi
0
Hello, I am designing a quiz application with the following database pattern. questions table: id, question, correct_marks, etc quizzes table: id, name, etc quiz_questions pivot table: quiz_id, question_id quiz_sessions table: id, session_uui...
surendrasahi surendrasahi
8
Hello, I have Six tables in a sequence and I want to join them with Eloquent relationships. While I am trying to do this Laravel throws an exception as Laravel accepts only one intermediate table in its relationships. Is there any possibility to join...
jaydeep replied
Solved
ahmadbadpey ahmadbadpey
3
Suppose I have a Conversation model like this : class Conversation extends Model { public function questions (){ return $this->hasMany('App\Question','conversation_id','conversation_id'); } public functi...
dacastro4 dacastro4
9
I'm trying to ignore all my $appends in my User model just for one time. I need all those every time on my app but this one time I don't need it and it's slowing down the performance of my query. If any can helping I'll totally happy!...
sakon54321 sakon54321
0
Hi, I'm trying to build a simple shopping cart API. I've noticed that when I use an eloquent relationship, like I'm trying to sum the value of a list of products that have been sold, the output (even though I only want the sum) is returning the whole...
hesselkramer hesselkramer
0
Hi All, I have 3 models User Pricelist Price 1 have 2 pivot tables priceslist_user and price_pricelist i now have user->pricelists working via pivottable by attach() only i want to do user-pricelists->prices. on pricelists i have a thisBelong...
Create a New Discussion Button