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
- Get count of filter data, while return a small set of records
- How to automatically update the timestamp of parent model in Laravel
- Call to a member function pluck() on null
- Submit form without CSRF token in Laravel
- Generate unique username in Laravel
- Retain selected value of select box in Laravel
- How to send ID to another page in Laravel
- How to add columns in existing table using migration in laravel
- Conditional validation in laravel
- Use withCount() to Calculate Child Relationship Records
- FirstOrCreate() Not Inserting Model
- Order by multiple columns in Laravel
- Get Array of IDs from Eloquent Collection
- How to validate website url in laravel using validaiton
- Update record after find method in lavavel
- Laravel order by date not working
- Get today records in Laravel
- On delete set foreign id column value null using migration in laravel 8
- How to authenticate admin users in Laravel ?
- Laravel save object to database
- Where to use whereNotNull eloquent in laravel
- Use of undefined constant laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- How to get last month records in Laravel
- In order to use the Auth::routes() method, please install the laravel/ui package