Source: levelup.gitconnected.com

CodeIgniter 4 CRUD Series with MySQL: Update

Category: MySQL, MySQL

Applications manipulate data that is in constant change. Are you a Medium member?

save(): This is a wrapper around the insert() and update() methods that handle inserting or updating the record automatically, based on whether it finds an array key matching the $primaryKey value: Recall in the ProjectsController.php Controller file, I have a updateProject() method with this code: I have also included a route in the Routes.php file for the ‘projects/update’ endpoint: $routes->post(‘projects/update’, ‘ProjectsController::updateProject’); I write a weekly email about SQL/PHP that I’m studying and interested in. If that sounds like something you would like to be a part of, learn more about it here (offsite link).

The update() method accepts 2 parameters, the primary key and an associative array of data (with matching keys for the tables’ columns).

However, if the Model update() method fails and returns false, the user is returned back to the ‘edit_project’ view with accompanying validation errors and data for this record.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners