本文整理汇总了PHP中app\Config::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::first方法的具体用法?PHP Config::first怎么用?PHP Config::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Config
的用法示例。
在下文中一共展示了Config::first方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Update config via POST
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
if (Gate::denies('set-config')) {
abort(403);
}
$config = Config::first();
$config->update($request->only('registration_enabled'));
return response()->json($config);
}
示例2: store
/**
* Associate the specified member resource to the group tuple
*
* @param Request $request
* @return Response
*/
public function store(Request $request, $groupId)
{
// Check config if registration is enabled
if (!Config::first()->registration_enabled) {
return response()->json(["msg" => "registrations are disabled"], 403);
}
$group = Group::findOrFail($groupId);
if (Gate::denies('attach-member', $group)) {
abort(403);
}
$this->validate($request, ['email' => 'required|unique:members,email|email|max:255', 'password' => 'required|confirmed|min:6', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'birthdate' => 'required|date', 'sex' => 'required|in:m,f']);
$member = new Member($request->all());
$member->password = Hash::make($request->input('password'));
$group->members()->save($member);
try {
return response()->json("ok");
} catch (\Illuminate\Database\QueryException $e) {
return response()->json("error");
}
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$cfg = Config::first();
// Check config if registration is enabled
if (!$cfg->registration_enabled) {
return response()->json(["msg" => "registrations are disabled"], 403);
}
$v = Validator::make($request->all(), ['name' => 'required|max:255|unique:groups', 'members' => 'required|array']);
for ($n = 0; $n < count($request->members); $n++) {
$v->sometimes("members.{$n}.email", 'required|email|max:255', function ($input) use($n) {
return count($input->members >= $n);
});
$v->sometimes("members.{$n}.password", 'required|confirmed|min:6', function ($input) use($n) {
return count($input->members >= $n);
});
$v->sometimes("members.{$n}.first_name", 'required|max:255', function ($input) use($n) {
return count($input->members >= $n);
});
$v->sometimes("members.{$n}.last_name", 'required|max:255', function ($input) use($n) {
return count($input->members >= $n);
});
$v->sometimes("members.{$n}.birthdate", 'required|date', function ($input) use($n) {
return count($input->members >= $n);
});
$v->sometimes("members.{$n}.sex", 'required|in:m,f', function ($input) use($n) {
return count($input->members >= $n);
});
$v->sometimes("members.{$n}.country", 'required', function ($input) use($n) {
return count($input->members >= $n);
});
//$v->sometimes("members.$n.cv", 'required|mimes:pdf', function($input) use($n) { return count($input->members >= $n); });
}
$v->after(function ($validator) use($request) {
if (count($request->members) < 1 || count($request->members) > 3) {
$validator->errors()->add('members', 'Only 1-3 members are accepted');
}
});
if ($v->fails()) {
return response()->json($v->errors(), 400);
}
// validate all members have correct auth or do not exist yet
foreach ($request->members as $m) {
$qm = Member::where('email', $m['email']);
if ($qm->exists()) {
// Check password
if (!Auth::once(['email' => $m['email'], 'password' => $m['password']])) {
return response()->json(["msg" => "User already exists, and password is incorrect", "offender" => $m['email']], 400);
}
}
}
$group = new Group($request->only('name'));
$group->save();
// create or register to the group all the members
foreach ($request->members as $m) {
$qm = Member::where('email', $m['email']);
if (!$qm->exists()) {
$qm = new Member($m);
$qm->password = Hash::make($m['password']);
$group->members()->save($qm);
// Handle cv PDF
//if ($m['cv']->isValid()) {
// $m['cv']->move(storage_path('app/cvs'), $qm->id.'.pdf');
//}
}
}
Mail::send('emails.admin.groupCreated', ['group' => $group], function ($m) use($group, $cfg) {
$m->from('eca-noreply@eestec.net', 'EESTEC Android Competition');
$m->to($cfg->admin_email, 'ECA Admin')->subject('New group registered!');
});
return response()->json($group);
}