如何将Laravel转换为Mysql插入触发器
我在Laravel-5.8的一个项目上工作 我有两个模型:评估算法类型(评估目标类型表)和评估算法(评估目标表)。当用户试图呈现一个名为evaluation_goals.index的视图时,该视图从evaluation_goals表中获取其数据,我想根据条件更新或创建到表中。代码如下:如何将Laravel转换为Mysql插入触发器,laravel,triggers,Laravel,Triggers,我在Laravel-5.8的一个项目上工作 我有两个模型:评估算法类型(评估目标类型表)和评估算法(评估目标表)。当用户试图呈现一个名为evaluation_goals.index的视图时,该视图从evaluation_goals表中获取其数据,我想根据条件更新或创建到表中。代码如下: $identities = DB::table('appraisal_identity')->select('id')->where('company_id', Auth::user()->co
$identities = DB::table('appraisal_identity')->select('id')->where('company_id', Auth::user()->company_id)->where('is_current', 1)->first();
$employeedeptId = DB::table('hr_employees')->select('department_id')->where('id', Auth::user()->id)->first()->department_id;
$goaltype = AppraisalGoalType::select('id','name','parent_id','max_score1')->where('company_id', Auth::user()->company_id)->where('is_visible', 0)->whereNotNull('parent_id')->first();
$data = AppraisalGoal::updateOrCreate(
[
'goal_type_id' => $goaltype['id'],
'appraisal_identity_id' => $identities->id,
'employee_code' => Auth::user()->employee_code,
],
[
'employee_id' => Auth::user()->employee_id,
'department_id' => $employeedeptId,
'weighted_score' => $goaltype['max_score1'],
'goal_title' => $goaltype['name'],
'goal_description' => $goaltype['name'],
'parent_id' => $goaltype['parent_id'],
'is_visible' => 0,
'company_id' => Auth::user()->company_id,
'created_by' => Auth::user()->id,
'created_at' => date("Y-m-d H:i:s"),
'is_active' => 1,
]
);
如何将Laravel代码转换为Trigger,以便每次当前用户希望查看评估_goals表中的itls数据时,上面的代码都实现为MYSQL Trigger(updateOrCreate)
或者有没有一种方法可以直接在Laravel中实现
谢谢