My table structure is like this: but now I want to move the gift to another table since the gift can be given to the users more than once in different dates. I have used $user->gift in many places in my project and I don’t want to change the code. So I want to create a method in User model
Tag: laravel
Insert price to the pivot table
I am trying to insert data to a pivot table order_serrvice using arrays I follow this code: https://blog.quickadminpanel.com/master-detail-form-in-laravel-jquery-create-order-with-products/ the column qty and service was inserted properly but the price does not, I dont know why? order_service table: OrderController: with dd($request): dd($price[$service]) Data base outbut Can any one help? Answer In your controller, you are misusing the attach() method: The attach()
Sql data vertical to horizontal and Laravel
hi iam getting data below like this but i want to display vertical to horizontal below like this how to achive this, can anybody help in this scenario, Answer Something like this will do it:
How to order by multiple columns not creating different groups using Laravel eloquent
I have a table which looks like this: Name AltName Sam null Ann null null Mark John null null Bart Sasha null I want to order by both Name and AltName. If I do this: This will return the data in this order: Ann, John, Sam, Sasha, Bart, Mark I don’t want it to group the data but instead merge
Laravel 8 Livewire search filter not working with first where clause
I want to have a table which shows all the data per company that has a filter search input, the problem is when I put the first argument where(‘company_id’, Auth::user()->company_id) it bugs out and doesn’t make the filter search work. This is my query for the table. Answer I suppose you want company_id filter to apply to all query and
How does a Laravel model get a “required” data? New column, adding another column’s data
Still new to laravel, learning how the $request interacts with create. here is my form for two of my variables for context: controller: model: my title and category_description is inserting fine with an auto incremented id column. What I am trying to do is just to add 2 columns: category_id and category_description_2 that just copies the value inserted by id
Convert SQL to Laravel ORM RELATONS
It is working but I should do with Relaion Like this… But it is not working because whereHas returns a collection, What I can do ??? Please give advice. Answer This is working thank you !!!
Laravel get array find collection and delete all
i need to get the id in the form of an array and delete it if they belong to user when trying to delete, I get this error Answer I think you can do it in very simple way i think
Display all data which are between these dates
So currently, I am trying to display a list of items which are not between date X and date Y. Let us assume that book_date_start = 2021-06-15, and bookdate_end = 2021-06-20 This is my current query: So based on this So basically as I was writing the above out, I realized that my query is WRONG, and since 2021-06-13 is
Delete unused groups in Laravel 8
I have a group model and I want to delete groups that don’t have any member. How can I get empty groups with eloquent or SQL query ? And this is the User model code: Answer I think whereDoesntHave work in you situation.