i have manytomany relation ship between categroy and product category model product model the pivot table what should i do after this i did not undrestant how attach will work in pivot table and return it with the product as json response ? edit this is the schema i am working on i want to give each product it’s own
Tag: laravel
how to determine if the ajax response is an array of key value pair or a simple string response
I have a simple ajax function that sends data to the server and prints the response. the problem is some functions from PHP send the response as an array while some functions send the response as a simple string. For example, if the function was a success then the response is received as a key of response and a simple
How to sort array with other arrays by date and take a limit in laravel and carbon
I have this array with other 16 arrays and so on… I want to sort the main array by date specified in “meta_date” field included on each “child” array, the sort can be $sort= “asc” or $sort= “desc” and I want to take a dynamic limit for the main array, for example if $limit=10 take the first 10 arrays sorted
The second dropdown value for multiple dropdown value NOT SAVE in database using laravel
Hye everyone! First of all, my coding all about dynamic dropdown value, the issues now is the second dropdown value is not save inside the database. Which part did I missed or wrong? View:- View for second dropdown using jquery script:- Controller:- Routes:- Answer The issue is with option value wrongly passed in jquery.It should be data[i].code instead of data[i].id
LARAVEL: I am only getting one item from my table when there are multiple items. How would I get all of them and output them?
I am using a session to create a basic cart. In the session there are multiple IDs ranging from 1-3. When I output the data using foreach it only outputs the first item from the table. I would like all the related items to appear. How would I go about doing that? Here is my index function from my controller:
Transform nested collection in laravel
I have a nested collection that I want to transform, pulling some keys “up a level” and discarding some other keys. Every item in the collection has an allergens property. I need to make each items allergens property, look like I’ve tried the following: But it doesn’t overwrite the allergens property Answer Since you’re posting your collection as JSON, I
How to calculate balance when the records I want to show in desc order?
I want to to show the recently created amount at the top but also I want to show the balance column, the balance column will add or subtract the amount from the record Controller Blade The problem with this is it starts adding from top, which I don’t want. I want it starts adding from bottom Expected results are marked
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint in laravel 8
hi i am trying to make category and then subcategory so if a category is deleted subcategory would also be deleted here what i have done so far created a model called category also created a subcategory model run the migration for the category in my subcategories migration i have defined the when i try to migrate i am running
how to use explode for an array of objects
I have an array like that: I want to do a foreach in “prerequis”: I need in second foreach to use in $value2[‘champ’] where $value2[‘champ’] is “tranche.fus.fup_id. So I need to explode that to have [‘tranche’][‘fus’][‘fup_id’]. How to use explode with that ? thanks everyone 🙂 Answer you can use laravel data_get helper:
Laravel 8 – Base table or view not found: 1146 Table ‘laravel8.brand’ doesn’t exist
I’ve been searching the web for quite a long time and I have tried adding the protected $table = “brands”; to my Brand Model as seen here: Then on my controller I have the following code: Passing this through my routes: Which I also used on my form inside views/admin/brand folder: My database table is named brands but adding protected