tovisbratsburg tovisbratsburg
18
I've been using MySQL for a while now and am pretty comfortable with it. I find myself using DB::unprepared() for Stored Procedures with a lot of the complex stuff just letting the database do its thing. Is there an advantage to using Eloquent in La...
mozziehin mozziehin
3
Hi there, I am trying to create a list of variation options, when it successful created the resources only show one of my data where by it should have two of it public function create(array $data = []): VariationOption { foreach ($data...
OskarB OskarB
4
I'm creating a Movie Database (like IMDB), where users can leave reviews on movies. Currently they're able to create and delete reviews, but I am not getting the update to work. I am able to make it work by redirecting the user to the Show blade for...
learningraph learningraph
2
Hi, My app is working fine localy with mysql but once I try to put it in production with pgsql I get the following error message when I do the migrations : Invalid text representation: 7 ERROR: invalid input syntax for type smallint: "learner&q...
ccasselman ccasselman
2
Trying to move my enterprise application to Laravel for the first time and running into what appears to be some long term maintainability challenges with Eloquent Models. Is there a way to get Eloquent/Laravel models to have private properties so all...
GodziLaravel GodziLaravel
4
Hello , $company = Company::find($id) ->update([ "company_name" => $request["company_name"], "former_company" => $request["former_company"],...
vrapan vrapan
5
Hello everybody, I watched a little while ago the episode about an audit technique of changes to tables. I am planning on using this but I have a few tables that I am planning on auditing like this that refer to lookup tables. So for example I have c...
cameronasmith cameronasmith
5
When you perform a delete on your model that has a polymorphic relation I would have thought it would also delete that parent or child's relation? Is this not the case or i'm I doing something wrong? Thanks, Cameron....
coder81 coder81
6
In a polymorphic relationship when I delete an item, the corresponding item, connected by a polymorphic relationship is not deleted. And becouse I can't set a foreign key, the only method to mantain the referential integrity is to delete this element...
armingdev armingdev
3
Hello everyone, I have an issue getting last record of the relationship. Il give one example: MODEL: public function parts() { return $this->hasMany(Parts::class, 'part_id'); } CONTROLLER: public function getLastCarPart()...
tykus replied
Solved
TerrePorter TerrePorter
2
is is possible to make a eloquent query from this. SELECT `users`.*, (SELECT COUNT(*) AS count FROM (`extra_purchases`) LEFT OUTER JOIN `users` `users_subquery` ON `users_subquery`.`id` = `extra_purchases`.`user_id` WHERE `users_subquery`.`id` = `...
Abdifatah Abdifatah
7
I have chapters Model ,I want to order by name like this Chapter 1 some text Chapter 2 diff text Chapter 3 some text Chapter 10 some text Chapter 20 diff text but it sorts like this Chapter 1 diff text Chapter 10 some text Chapter 20 some text Ch...
booni3 booni3
3
I have the relationship: public function collectionAddress(): BelongsTo { return $this->belongsTo(OrderAddress::class, 'collection_address_id'); } In some parts of my app, the relationship does not exist but I want to load in...
mvinayakam mvinayakam
2
I recently discovered the way to fetch children and grandchildren with this beautiful helper. Context - This is a self referencing table. Collection::get()->wherePosition('main-nav') ->whereLevel(1) ->orderBy('sequenc...
AccountDeleted AccountDeleted
4
I have 2 eloquent classes ("Order" and "OrderProducts"). I simply need to create an order with a product. Order Class class Order extends Eloquent { public function items() { return $this->hasMany(OrderProducts:...
gianmarx gianmarx
18
when doing this query at the model level i get the following error: Error #1250 - Table ok' from one of the SELECTs cannot be used ORDER clause this is the model-level query: public function ok() { ; }...
amrcodes amrcodes
4
Any idea how to deal with the following scenario? I made a JS script that generates multiple sections up to 10 sections each section have identical inputs for details. So, when the user select x amount of sections, the script generates the entered am...
Snapey replied
Solved
mansoorkhan8 mansoorkhan8
5
Hi, I need some help! On line number 3, I want to pass student.level_id (dynamic value from within the query results) in where('level_id', ??) dynamically. Any idea How should I do it? In other words, I want to convert this SQL query to Eloquent: SEL...
ivqonsanada ivqonsanada
2
I have User and Experience Model, i want to call a function in Experience Model within User Model, but it give me an error: Call to undefined method Illuminate\Database\Eloquent\Relations\HasOne::awardExperience() User.php public function getExp...
chrismay chrismay
3
I am currently victim to gap locks in MySQL: http://thushw.blogspot.com/2010/11/mysql-deadlocks-with-concurrent-inserts.html Simply retrying could be a solution to my problem. I see that there is a separate parameter on transactions: DB::transaction(...
MeisamTj MeisamTj
1
Hi there, I have a model of Products. I made new model for administration purpose and named it AdminProduct. When I try to get images of a product by morph relationship it returns empty array. It tries to select from 'images' table where type is equa...
tovisbratsburg tovisbratsburg
10
Stored Procedures are a good way of letting your mysql server handle complex queries and such. Stored Procedures can have in out and inout within the call. Is there a good way of working with all 3 in Laravel 8, or do you have to write something cust...
tovisbratsburg tovisbratsburg
5
Curious, are there any Table Names that I'll want to stay away from. I have jobs, so I want to be able to create a table named jobs, but it looks like queue in laravel might create its own down the road. Is there a list of table names I want to stay...
mvinayakam mvinayakam
4
public function children() { return $this->hasMany(Collection::class, 'parent_id')->orderBy('sequence'); } public function products() { return $this->belongsToMany(Product::class)); } I have a Collect...
Binho Binho
21
Hello everyone, Since many days I'm trying to make a complex request to filter some values but without success. I'm here now to find some help and if you have a some answers for me :) I have a table "user_working_locations" to store default...
Abhimanev Abhimanev
3
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...
iamamirsalehi iamamirsalehi
6
Hey there, I have a table that has a lot of data, I wanna get the last data of the day for the last week. Could you please help me with how to solve it? Thanks in advance...
trin replied
Solved
need_a_hat need_a_hat
1
I have a statement that works directly in MySQL but not in laravel. I'm using Laravel 8. My model is that I have topics, which have many posts, which have a many-to-many users via pivot table post_user. That pivot table is where the up votes are stor...
derekmd derekmd
6
This thread is more an extension of https://laracasts.com/forum/?p=431-eloquent-relation-setup-two-foreign-keys-to-same-table as I have a messages table containing two foreign key sender_user_id and recipient_user_id that both reference the users tab...
slothentic slothentic
0
In the docs, from this example: use Illuminate\Database\Eloquent\Builder; $posts = Post::whereDoesntHave('comments.author', function (Builder $query) { $query->where('banned', 0); })->get(); It looks like there should be some way to exclu...
ajfick ajfick
1
I'm working on a site related to Dogs where I've got a model called "Breed". I need to be able to connect "related breeds" to one another. An example of this would be "Poodle" and "GoldenDoodle". My issue is, I...
tms1987 tms1987
0
Hello, I am looking for a way on how I can create a booking history for my users. Assuming, I have a PaymentHistory-MySQL-Table, consisting of id, user_id, timestamp, description and price. As my website is available in multiple languages, I am looki...
arctushar arctushar
0
Hi I have a table name store, which has below field id, buyorfree, product_id, price, quantity. note:buyorfree is enom of buy,free and sale table which has below field id, store_id, rate, quantity Now I want to get those store record where and buyorf...
localpathcomp localpathcomp
1
The union query works great & is correct but seems quite slower. $first = auth()->user() ->notifications() ->where('data->matter_id', 7); $notific...
tms1987 tms1987
1
I'm just working on the Role and abilities features as described in the Laravel from Scratch video: https://laracasts.com/series/laravel-6-from-scratch/episodes/54 Here, I want to add a list of users who have a role to my admin panel. (Later on I wil...
apex1 replied
Solved
Create a New Discussion Button