I'm building a CRM and I have a list of customers.
When I create a customer, I usually insert it as a draft as soon as the user clicks on "Insert button". Why? Because I want the user to be able to insert photos and documents on the insertion form. This way, I have the customer ID already and I can process the upload using that ID.
The problem here is that we can have multiple drafts at a certain moment.
My question is: is there any better method to do this? Without creating the draft? For instance, using a temp folder where the photos and documents are temporarily saved?
EDIT:
the issue woth having multiple drafts is that at certain point will may have a lot of trash.
I mean, this works for me ok? And it's a solution I have, I just wanted to know if there's a better solution instead of using drafts.
It depends on what exactly you are using to save the customer in the database.
If you are using an ORM such as Eloquent or Doctrine you just need to have the correct relationships between Entities and you won't need to save the Customer as draft, you can just flush all of the information at once.
If you aren't using an ORM, you can still do it in one request, just insert the Customer record first and get the last inserted ID , for example if using PDO, you can use PDO::lastInsertId https://www.php.net/manual/en/pdo.lastinsertid.php .
After you have the ID just set it to the other columns where you need it.
Related
I'm using Laravel 9 with php 8.1 in a pretty advanced project. In this project I have a parent form which allows a purchase order document to be created. The po document has at least one child row which is added by clicking an add button using livewire. However when this is saved the document it belongs to has not been created and thus no id i can use. So how would you guys handle such a form?
I'm considering a temporary id which I think is my best option. I had considered using the user id here but if I as the user have 2 such forms on the go then I wouldn't know which are the correct rows to amend with the document id, worse if I've added rows and get logged out these rows will be unattached.
Another option would be to create the document but as it stands it would fail validation due to there being no associated rows.
I'm struggling to find a strategy to deal with this scenario. In a previous project I used an is_draft flag for a similar scenario but it left orphaned items if the process was not fully completed.
thanks
You could refactor the view so Livewire controls both the purchase order form and the child row(s). Then Livewire would be able to keep the rows in their unsaved state until you save the parent form, at which point you'd also associate the rows and save those.
If the data is tightly coupled and interdependent then I would go for that approach.
I initially came across a composer package called cjmellor/approval (https://github.com/cjmellor/approval) but quickly realised it was far more than I needed but it did inspire me to into thinking of storing the raw data to use later.
After some thought I decided to create an stdClass to hold the required data for each row in the array and add/update this while creating the PO. I 'saved' this into my cache (I use redis in this app) with a 2 hour expiry. I then updated this cached array in livewire until the form was saved at which point I get the cached array data and updated the po data table with the cached data.
Say I have a list of clients with their client IDs and other information and I want to add multiple clients to one batch/order. The order table would dynamically propagate on the webpage with small order summary tickets for each order, and then when clicked on show more info about the order including all the client IDs and other information associated with it.
The functionality will include adding and removing the users from the specific orders, and obviously storing them to be recalled again
I'm new to PHP and SQL, I can propagate the client table and order tickets well dynamically, but Google has only taken me this far.
The best solution I came up with is to store a list of the users ids in a new row of the order table and write PHP script to edit it. Is this possible? Or even a good way of going about it? Any advice will be much appreciated.
One of my clients needs to connect Active Campaign to their database so that when new fields (mainly name and email address) are added those contacts are automatically imported to either an Active Campaign's list or an automation.
It would be ideal that this migration process was selective. I mean, no all contacts added on the database should be imported to Active Campaign but only those we need. I don't know if that can be done by previously adding some classes to those contacts. Other option would be to add those people into a specific database.
I have found 2 articles from Active Campaign's blog but I am not sure which one is better to follow:
https://help.activecampaign.com/hc/en-us/articles/115000841130-Database-sync-for-importing-contacts
https://help.activecampaign.com/hc/en-us/articles/115000720584-Automatic-import
By following the second one you can connect Active Campaign to a database with Zapier which can simplify the problem but I think the options are more limited.
Can you please advice based on your previous experience?
Thanks!
I see two possible solutions here:
You can modify your client's code.
In this way what you simply need to do is that after the database insert you just add a line or two to add the new contact and assign it to a list. I imagine there are different fields that get filled so you could also assign custom field values and tags.
You don't have access to the code, but you have access to the database
This way what you could do is add a flag column to your contacts database. The flag would show whether the contact has been processed or no. So after that you create an automatic process / cronjob that runs let's say every 5 minutes and only selects the contacts that have the processed flag = 0. This way you just get the data and do the same thing as in step 1 - create contact, assign to list, add custom field values and tags.
You could also do this step using Node.js (I'm no pro so I would't be very specific on this topic) but you would basically create a process that runs when a new database entry is inserted and does the stuff described in step 2. Basically a webhook on your side.
I am creating a site and i am making a general option page for the site that include the site name, logo, social links so that i can manage them dynamically from one place without changing the links and text in all pages where i called them.
What I want is that the table i created in database, i want to have only one row in it. If someone try to add other row of data it should not be added because i have to call only one data for the site.
I hope the query is clear to all.
Thanks for your support. Help me if u can. please :)
By,
if someone try to add other row of data it should not be added
what do you mean? Are you trying to avoid unauthorized access? If yes, then you need to implement roles https://laracasts.com/discuss/channels/general-discussion/roles-and-permissions-in-laravel-5
To manage your site information, I'm sure you set a form that will be used to update the site info. And from the look of things you will only be updating that row when you hit save or update button. I don't think you will be doing full CRUD here just updating so there'll be no chance of inserting a new row of data in the db.
So three things:
you want to create a migration, seed the table with the site details accordingly. run the migration
you want to make sure the user trying to access this route is authorized to do so
you want to pre populate the site info in the form fields when the edit site info page loads and you want to save the form when the authorized user changes any of the site info
This way, there'll be no question of stopping further insertions into the db.
I'm currently developing a database/website server interface to facilitate inputting data for a data collection project. There are two types of additions being made to the database: A and B here. Some of the tables in the database that handle these entries are as follows:
dcs_projectname_a
dcs_projectname_b
Each of these have tables for all the required input fields in addition to things like creator, timestamp, etc.
The pages on the website facilitate three different options: add, view, and edit. Each page for each type of entry performs the respective function. That is, the add page adds, view page views, etc.
I am just about done; however, there is a major challenge I haven't really confronted yet: concurrency. There will be multiple users adding content to the database at the same time. Each entry is given its own specific id and there CANNOT be any duplicate id's. That is, the first a entry is A000001, the next is A000002, and so on.
On the add and edit pages, there is a disabled field for the user to view the id for other uses when physically documenting entries.
What I need to figure out is how to implement concurrency management so that when users are concurrently adding a's that they will not be under the same id and row.
The add page automatically generates the id to be used by accessing the database's most recent id and adding one.
My thought was to create a new row in the table every time the add page is opened and give it the calculated id. Then, when information is added it performs a modification to that existing row. This way, if another user opens the add page while another entry is currently being added it will be given the future id, not the same one.
With this method I need a way to delete this entry if the user leaves the add page or closes the browser. Then, I also need other users with open add pages to automatically update their id's to one less when the first user (or any other user less than the most id being used) leaves their add page and cancels the addition.
This is kind of a complicated explanation and if you don't understand let me know and I'll try to answer as best as I can. Any help is much appreciated!
Thanks
There's a number of solutions to your problem, but you seem to have made things harder by having your application generate the record IDs for you.
Instead, you could just be using MySQL's AUTO_INCREMENT functionality to automatically generate/increment the record ID for you (upon insert). MySQL will ensure that there are no duplicates, and you can get rid of the extra database call to retrieve the most recent ID.