I’m using method in my model to mutate a single response to my client When call product Laravel using this method name by default? Debugger show this area: C:xampphtdocs…/…vendorLaravelframeworksrcIlluminateDatabaseEloquentConcernsHasAttributes.php:521 How can I resolve this error? Answer in my case i use a reserved method name in my model for example i define a new attribute() method for my one to
Tag: eloquent
How to make Eloquent model attribute updatable only through public methods?
I want to prevent a model attribute from being directly set from an outside source without going through setters that control the logic. This should not be allowed: You must use some kind of accessor or setter method: But I don’t care how you get the value: How do I enforce that the only way to update this attribute would
Store product multiple colors to the database Laravel
I have a product table which has price, name, stock etc. and color_products table which has color_id, product_id. I want to store a product to the database with selected colors so far I’m getting an error Invalid argument supplied for foreach(). How can I fix this? Controller Blade file Answer try to rename your select field to be something like
Query a model using a relationship
I have a model called unit that has this relationship In the UserData model there is a column called user_id which I am trying to put in my condition in my query. I am trying to do a query like this but there is no user_id column in the Unit table, only though the users relationship Answer Ended up doing
Limiting retrieved columns when using withPivot on belonsToMany relationship
I have a model called Shifts with a belongsToMany relationship to a shift_employee table that acts as a pivot table to record applications for employees to shifts. I also have a scope so that I can return applications with shift objects. Here is part my Shift model: My shift_employee pivot table is pretty simple and the structure is shown below.
Use Laravel Eloquent joining
Hello I want to retrieve only rows of quizzes that the student didn’t take yet When he completes a quiz the variable done in QuizStudent table is going to become 1 Quiz table My relationships: …
Get orders of a user with orderItems and product details in Laravel
I have 3 tables (foods, orders and orderItems). I want to get orders of a user with orderItems and foods, but i failed. Here’s a result what i am getting right now, but i need to get food details …
How to correctly specify the relationships between Eloquent Models
I have the following Models ReleasePackages
why am i getting null value from my database in laravel when trying to find specific user?
Am trying to display information of a specific student in my database using student ID. I seem to get null value yet the student exist in the database. i seriously do not know why am getting this null …
Put data in the method (addItem) using foreach
Code i tried but it display 1 value. I want to use addItem to insert more data and display it on my invoice pdf. I can grab all my data using eloquent but dont know how to insert into the class given. …