Touch parent updated_at in Laravel
Touch parent updated_at in Laravel
With this article, we’ll look at some examples of how to address the "Touch parent updated_at in Laravel" problem.
It will help you to update the updated_at column data of the parent table while updating the data of the child table. Like we make a comment on a specific post and we want to update the updated_at column of the related (post) records of the posts table then it will help you to do so-
Add touch property to child model to update the parent relationship to renew
--PATH app\Models\Comment.phpclass Comment extends Model { protected $touches = ['post']; }
It will update the updated_at column of the related record of the posts table if you make a comment on this particular post.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to get last year records count with month wise in Laravel
- Send post data from controller to view
- Target class [admin] does not exist.
- Laravel get all records with pagination
- How to validate website url in laravel using validaiton
- Pass value from controller to model in laravel
- How to increment column value of table in Laravel
- Ajax GET request in laravel
- Laravel 11 project setup on localhost using breeze with blade step by step
- Laravel form request validation
- Retain selected value of select box in Laravel
- Remove public from url in laravel project
- Symlink(): No such file or directory
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to create projects method with belongstomany relationship in user model
- Laravel 10 Breeze Authentication Example
- Redirect to previous page or url in laravel
- Use withCount() to Calculate Child Relationship Records
- Call to a member function pluck() on array
- How to fetch single row data from database in laravel
- How to change default timestamp fields name in Laravel
- Target class [HomeController] does not exist
- Print last executed query in laravel
- How to add foreign key in laravel using migration
- How to create pivot table in laravel using migration