本文整理汇总了PHP中app\models\Group::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Group::findOrFail方法的具体用法?PHP Group::findOrFail怎么用?PHP Group::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Group
的用法示例。
在下文中一共展示了Group::findOrFail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
public function edit($id)
{
$group = Group::findOrFail($id);
if (Request::isMethod('get')) {
return view('admin.group_edit', ['group' => $group]);
}
$validator = Validator::make(Request::all(), $this->rules, $this->messages);
if ($validator->fails()) {
return redirect()->route('group_edit', [$id])->withInput()->withErrors($validator);
}
$group->title = Request::input('title');
$group->titleEng = Request::input('titleEng');
$group->text = Request::input('text');
$group->eng = Request::input('eng');
$group->link = Request::input('link');
$group->position = Request::input('position');
$group->enabled = Request::has('enabled');
if ($file = Request::file('photo')) {
$group->photo = $this->upload($file, 'photo');
}
if ($file = Request::file('partners')) {
$group->partners = $this->upload($file, 'photo');
}
$group->save();
return redirect()->route('group_edit', [$id])->with('msg', 'Изменения сохранены');
}
示例2: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit(Request $request, $id)
{
//
$oGroup = Group::findOrFail($id);
// 需要更新的组
$powers = Group::get_group_power($id);
// 组拥有的权限
$oAllPowers = Power::select(['id', 'category', 'name'])->get();
// 全部的权限
// 按分类分开
$aCategoryPowers = array();
foreach ($oAllPowers as $k => $v) {
$aCategoryPowers[$v->category][] = ['id' => $v->id, 'name' => $v->name];
}
if ($request->isMethod('get')) {
return view('admin.group.edit', ['group' => $oGroup, 'power_categorys' => $aCategoryPowers, 'powers' => $powers]);
}
// post
$sGroupName = $request->input('groupname', $oGroup->groupname);
$aGroupPower = $request->input('powers', array());
$aAllPowers = array_column($oAllPowers->toArray(), 'id');
try {
$j = count($aGroupPower);
for ($i = 0; $i < $j; $i++) {
$aGroupPower[$i] = intval($aGroupPower[$i]);
if (!in_array($aGroupPower[$i], $aAllPowers)) {
// 权限不存在
unset($aGroupPower[$i]);
}
}
} catch (Exception $e) {
App::abort(404);
}
// 超级管理员的权限永远是所有,无法更改的
// 只有名字可以修改
if ($oGroup->id != 1) {
Group::update_powers($id, $aGroupPower);
}
$oGroup->save();
session()->flash('msg_success', '修改成功');
return back();
}
示例3: getGroup
public function getGroup()
{
$group = Group::findOrFail(static::user()->group_id);
return $group->name;
}