i’m kind of new to laravel first time developing on it. My goal is to get some filtered events to show, the filters should all work together (‘filter 1’ AND ‘filter2’ ecc..) even when some are empty. The problem that i’m getting is that when my filter fields are empty the query won’t return any event. My CONTROLLER code: More
Tag: eloquent
Determine selected options based on many-to-many relationship
I have three tables: products, categories and category_product. In my edit form page I’m displaying the categories and subcategories values in a select box. The chosen category options are saved in the pivot table category_product. This table has product_id and category_id. Here’s my code. Product model Category model: edit product page view: subcats-select view How can I put “selected” attribute
How to make relationship between three table in laravel eloquent
I have three tables, Sections,Questions and options. Each Section has many questions and each question has many options. How can I fetch data from this tables related to each other? Section model relationship with Question model Question model relationship with Option model: my query: It returns this: I want each questions member contains options array related to it. Answer You
Laravel filter relationship data
Code Data return Question: I tried to filtering data that if a relationship “getCauserDetails”, How can I not show the data if the relationship name is only found “test” or should I say null? So on the example output, it displays all the data, but I want to only the data that I filter just retrieve. Answer Because of your
Laravel update model’s one-to-many relation’s items
I have two Eloquent models: Item’s columns are id, userId and name. When I want to update the user (PUT /users/<id>) I also want to update the items in the same request, meaning: Skip existing items Add new items Remove extra items Afterwards both DB and the relation should have up-to-date items. Example of the request data: I tried to
How do I create a eloquent Polymorphic relation
I have a two eloquent models model User and Retailer. I want to create a new model “Task” where there there should be a field “added_by” which can denote either a user or a retailer. How can I create the migration for Task so that there is a field that can denote either user or retailer? How can I create
Laravel patch method not supported (even on update method)
HTML PATCHING FORM {{ Form::model($model , [ ‘route’ => [‘admin.friendship.update’, $model->id] , ‘class’=>’needs-validation ajax-form’, ‘method’ => ‘post’ ]) }} @…
How to multiple withcount() columns sum and order by in laravel
I have to need to order by records based on withcount() function in laravel 6 In this code, I have two withCount() functions and I need to order By based on that two-column sum before get(). It works when order by using one column but if I use two-column then it returns an unknown column. Is it possible or not?
Retrieving data from pivot table in Laravel only using one foreach loop
I have created the 3-way pivot table for Users, Shifts, Patterns. It is called pattern_shift_user. [pattern_shift_user.][1] It refers to the three models via many to many relationships here’s a view of the user model that links the pattern model and shift model [User Model][2] I have done the same for each model, and it seems to work, the problem I
how to get all user based on where condition and compare this result with another condition in laravel eloquent
I have a user table column referred_by: I have a view for step 1 user like where referred_by=auth::user()->id In here whoever registered by this user referal link will be shown in this table: I …