Hello im trying to do a quiz app with laravel and im struggeling with retrieving my questions with category.. i have a unsightly solution with this but it’s not dynamically.. public function …
Tag: eloquent
How to add new method chaining for Laravel Eloquent?
I try to add new method for simplify and reusable code but I failed User Model : public function products() { return $this->hasMany(‘AppProduct’); } public function obsolate() { return $…
Property [articles] does not exist on this collection instance
I have this code in my model called Tag: <?php namespace App; use IlluminateDatabaseEloquentModel; class Tag extends Model { protected $fillable = [ 'tag' ]; public …
Problems specifying Laravel Eloquent database at runtime
Laravel 5.8. I am trying to save an Eloquent model, choosing the database connection at runtime: My config/database.php file: My problem is that each time I run this code, the cat is created in the mysql (default) database, rather than the staging database, even when USE_STAGING is true. Answer The problem is the static call of the create() method. By
Laravel Eloquent – how to get only 2 child of each parent using Eloquent?
I want to get category with only 2 subcategory not all subcategory. Like below output Category 1 subcategory 1, subcategory 2, Category 2 subcategory 1, subcategory 2, Category 3 …
How to append or attach a pivot relationship to a model?
I am trying to get the practice area record of lawyers from practice_areas table along side each time I get a lawyer’s record from lawyer_profiles_table. This two tables (practice_areas and …
Laravel 6: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
everyone! I need some help. I’m creating a web app in laravel 6 that lets the user insert data through php forms that is also inserted into a database. Basically, I create a Supplier (it’s working), …
How to resolve null return in Laravel query?
Given my Models Person and Student. Now, one of my controller is doing this: $person_id = AppModelsPerson::insertGetId([‘name’ => $request->name, …]); AppModelsStudent::create([‘…
Update multiple row with insert new data in laravel
I am new to Laravel, here my existing fields are getting updated but unable to insert a new row, when users checks for a new category it should be added as a new row in the database. public function …
Laravel Eloquent Relationship between users table and states table with states_id in users table
I am trying to figure out relationships in laravel and have come to the end of my rope so I thought I would post my very first question here in hopes of figuring it out. I can generally find the …