I found several ways to do what I need to do, the first way was using the rounting using the web.php file. But according to serveral posts this creates vulnerabilities in the application. So I found out the correct usage is with a controller that manages the database queries. I created a controller, named EventsController and put this into it:
Tag: laravel
Laravel 8.x – How to use updateOrCreate with a where clause?
I am trying to use Laravel updateOrCreate to update a record if its within this month and last month based on if an ID exists. If the ID exists, and the result is in this current month or last, a new record is created instead of updated. Expected input: 1 (which exists from last month) Expected output: Record is updated
Race condition with multiple updates PHP & MySQL
I have a table called cards, Each user can create/have multiple cards. One of the cards must be set as default. Sometimes when a user performs multiple requests to set another card as default at the same time, In the end, There are two or more default cards. Initial table: id user_id is_default 1 50 0 2 50 1 Requests
Session put does not seem to be working properly
I’m working with Laravel 5.8 and I wanted to make sure that users can submit a form only every 2 hours (as long as a session is alive). So I tried this at the Controller: So by this, everytime a user submits a new request, session request_has_been_sent must be set. Therefore at the next time user submits the form, if
Split assoc array by keys
I have data like this: I want to separate it into 3 different arrays like so: For the life of me i just cant seem to wrap my head around this today, I have tried doing loops and while/if using “array_colum()” but I cant get to add a 0 for the entry that does not have a matching date. PS:
Laravel translations
can someone tell me how can I search (with livewire) products which have a translatable title? Currently, I am using astrotomic/laravel-translatable package. Translations are working just fine and I can statically pull the right data but when I try to search it I have an issue because the package is expecting to have a title in a different table and
Call to a member function store() on null Laravel 8
When I click on save to update the data on my edit page, I get the following error. call to a member function store() on null Answer As a result of $request->file(‘file’) is returning null, and you are trying to call a method on null, resulting in the exception. Due to the way Laravel handles PUT and PATCH requests, you
Change image with and js
I have a small slider that switches the preview image to the main image. It works fine now blade.php js But I still have a picture mobile_image, and I want the mobile_image to change instead of main_image at the maximum size of 576px, for this I use <picture> I change my code to like this But my slider just stops
when sent data via Ajax to a Controller in Laravel the data is null
I have used Ajax to sent data to the controller, unfortunately when I retrieve data it’s empty nothing is sent. although it does give me the data when I get it via JQuery before it’s sent. below is the code of Ajax ——————- —————–Laravel Controller method which receives the data —————- Answer I have found the answer, instead of using
Is mass assignment protection needed when properly using validation?
I’ve been using Laravel (5.4) and PHP both for the very first time in a legacy app I’ve been tasked to maintain, and over the past couple of months I have noticed a pain point, which is mass assignment. I believe I have a well-enough grasp of what is is, but I am not sure if I am really utilizing