Search
 
SCRIPT & CODE EXAMPLE
 

PHP

touches in laravel

/*
When a model has a BelongsTo or BelongsToMany relationship with another model, 
Let us say Comment that belongs to a Blog, it could in some cases be helpful
to update the parent’s timestamp when the child is updated.
This can be done by adding the relationship to the $touches attribute.
*/

class Comment extends Model
{
    protected $touches = ['blog'];

    public function blog()
    {
        return $this->belongsTo(AppBlog::class);
    }
}

/*
In Case we only want to Update One Model without needing change in other Model
ie Update updated_at without updating other fields
See the code here:
*/
public function updateUpdatedAt(){
  $user = User::find(1);
  $user->touch();
}
Comment

PREVIOUS NEXT
Code Example
Php :: php str starts with 
Php :: what is lang in laravel 
Php :: laravel rate limit 
Php :: Invalid credentials. symfony 
Php :: Get data from array (from an API) in Laravel 
Php :: if statement php 
Php :: upload image to database laravel 8 
Php :: laravel db query log string replacements 
Php :: laravel how to nested foreach 
Php :: download file using jquery php 
Php :: Laravel PackageManifest.php: Undefined index: name 
Php :: Try raising max_execution_time setting in php.ini file (CentOS path is /etc/php.ini): max_execution_time = 300Fix 504 Gateway Timeout using Nginx 
Php :: fakestore api data in laravel 
Php :: Write a php program to perform sum of two numbers 
Php :: Laravel Max Helper Function 
Php :: laravel transactions eloquent 
Php :: cara membuat koneksi php 
Php :: Form::select laravel 
Php :: php strip url of all invalid characters 
Php :: heap sort php 
Php :: app url laravel 
Php :: get 2 hrs before data in php 
Php :: stampare array php foreach 
Php :: recursive directory only listing php 
Php :: eloquent firstorcreate 
Php :: php ifelse 
Php :: octobercms mail view 
Php :: mysql between all months days even null 
Php :: php loop through obect 
Php :: Unable to do sum and getting same value by using while loop php 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =