gpt4 book ai didi

php - 如何使用 Laravel 5.2 以相同的方法添加和更新表行

转载 作者:行者123 更新时间:2023-11-28 23:25:47 25 4
gpt4 key购买 nike

我需要使用 Laravel 5.2 在 My Controller 中的一种方法中插入数据和更新表格行。我的表名是“权限”。这是我的方法:

public function addPermission(Request $request, $id,  Permission $permission)
{
if ($permission = Permission::findOrFail($id));{
$this->validate($request, [
'status' => 'required'


]);

$permission = new Permission;

$permission->status = $request->input('status');
$permission->project_id = $id;

$permission->collaborator_id = $request->input('cid');

$values = $request->all();
$permission->fill($values)->save();

return redirect()->back()->with('info','Permission has been updated to your Collaborator successfully');
}
else {

$this->validate($request, [
'status' => 'required'


]);

$permission = new Permission;

$permission->status = $request->input('status');
$permission->project_id = $id;

$permission->collaborator_id = $request->input('cid');
$permission->save();
return redirect()->back()->with('info','Permission has been added to your Collaborator successfully');

}
}

出现以下错误

syntax error, unexpected 'else' (T_ELSE)

我做错了什么?

最佳答案

语法错误

if ($permission = Permission::findOrFail($id)); { ......

只需删除“;”

if ($permission = Permission::findOrFail($id)) { .....

关于php - 如何使用 Laravel 5.2 以相同的方法添加和更新表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39408232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com