本文整理汇总了PHP中app\App::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP App::findOrFail方法的具体用法?PHP App::findOrFail怎么用?PHP App::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\App
的用法示例。
在下文中一共展示了App::findOrFail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, Request $request)
{
//$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed.
$app = App::findOrFail($id);
$app->update($request->all());
return redirect('admin/apps')->with('success', Lang::get('message.success.update'));
}
示例2: start
private function start($message, $tg)
{
$key = trim(str_replace('/start', '', $message['text']));
$token = Token::findByToken($key);
$app = App::findOrFail($token->app_id);
try {
$auth = Auth::findByAppAndTelegramUser($app, $tg);
} catch (ModelNotFoundException $e) {
$auth = new Auth();
$auth->app_id = $app->id;
$auth->telegram_user_id = $tg->id;
$auth->email = 'a' . $app->id . 't' . $tg->id . '-' . generate_email() . '@telegramlogin.com';
}
$auth->access_token = generate_access_token();
$auth->active = true;
$auth->save();
$code = Code::create(array('app_id' => $app->id, 'auth_id' => $auth->id, 'code' => generate_code()));
$url = $app->redirect_url . '?code=' . $code->code;
if ($token->query_string) {
$url .= '&' . $token->query_string;
}
$text = 'Please click this link to finish your signup at *' . $app->name . '*: ' . PHP_EOL;
$text .= '[Click here](' . $url . ')';
$params = array('text' => $text, 'chat_id' => $tg->telegram_id);
$this->send($params);
$token->delete();
if ($app->client_id == 314159265) {
$tg->status = str_replace('state=', '', $token->query_string);
} else {
$tg->status = 'access_granted';
}
$tg->save();
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Requests\AppRequest $request, $id)
{
$app = App::findOrFail($id);
$app->fill($request->all());
$app->save();
return redirect('dashboard');
}
示例4: start
private function start($message)
{
$key = trim(str_replace('/start', '', $message['text']));
$token = Token::findByToken($key);
$app = App::findOrFail($token->app_id);
$from = $message['from'];
$telegramId = $from['id'];
$telegramName = $from['first_name'];
if (array_key_exists('last_name', $from)) {
$telegramName .= ' ' . $from['last_name'];
}
if (array_key_exists('username', $from)) {
$username = $from['username'];
}
try {
$tg = TelegramUser::findByTelegramId($telegramId);
} catch (ModelNotFoundException $e) {
$tg = new TelegramUser();
$tg->telegram_id = $telegramId;
}
$tg->name = $telegramName;
$tg->save();
if ($tg->status != '/start') {
$tg->status = '/start';
$tg->save();
if (isset($username)) {
$tg->username = $username;
}
try {
$auth = Auth::findByAppAndTelegramUser($app, $tg);
} catch (ModelNotFoundException $e) {
$auth = new Auth();
$auth->app_id = $app->id;
$auth->telegram_user_id = $tg->id;
$auth->email = generate_email() . '-' . $app->id . '-' . $tg->id . '@telegramlogin.com';
}
$auth->access_token = generate_access_token();
$auth->active = true;
$auth->save();
$code = Code::create(array('app_id' => $app->id, 'auth_id' => $auth->id, 'code' => generate_code()));
$url = $app->redirect_url . '?code=' . $code->code;
if ($token->query_string) {
$url .= '&' . $token->query_string;
}
$text = 'Please click this link to finish your signup at *' . $app->name . '*: ' . PHP_EOL;
$text .= '[Click here](' . $url . ')';
$params = array('text' => $text, 'chat_id' => $telegramId);
$success = false;
$trys = 0;
while (!$success && $trys < 5) {
$success = $this->send($params)['ok'];
sleep(1);
$trys++;
}
$token->delete();
if ($app->client_id == 314159265) {
$tg->status = str_replace('state=', '', $token->query_string);
} else {
$tg->status = 'access_granted';
}
$tg->save();
}
}