Hi @supunsam , if you want to create a reference for created user and modified user you can define a relationship for this. You can follow the code below.
In your controller
public function store(Request $request,Model $model){
$data = $request->all();
$data['user_id'] = auth()->user()->id;
$model->create($data);
return ........
}
public function update(Request $request,Model $model){
$data = $request->all();
$data['modified_user_id'] = auth()->user()->id;
$model->update($data);
return ........
}
and then in your model
public function created_user(){
return $this->belongsTo(User::class);
}
public function updated_user(){
return $this->belongsTo(User::class, 'modified_user_id');
}
and your database should like this,
| ...... | user_id | modified_user_id |
you modified_user_id column should nullable,
then you can call the relationship like this,
$model = Model::find(1);
$created_user_name = $model->created_user->name
$updated_user_name = $model->updated_user->name