本文整理汇总了PHP中app\models\Account::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Account::save方法的具体用法?PHP Account::save怎么用?PHP Account::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Account
的用法示例。
在下文中一共展示了Account::save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initAccounts
public function initAccounts()
{
//create default account for balance Item
$account = new Account();
$account->name = $this->name;
$account->balance_item_id = $this->id;
$errors = [];
if ($account->save()) {
//for all existed balance items create amount for default account
$bSheets = BalanceSheet::find()->all();
$success = true;
foreach ($bSheets as $sheet) {
if (isset($sheet->id)) {
$amount = new BalanceAmount();
$amount->account_id = $account->id;
$amount->balance_sheet_id = $sheet->id;
$amount->amount = 0;
if (!$amount->save()) {
$success = false;
$errors['amount'] = $amount->errors;
}
}
}
if ($success) {
return false;
}
} else {
$errors['account'] = $account->errors;
}
$errors['message'] = "Errors in BalanceItem::initAccounts()";
return $errors;
}
示例2: login
public function login(Request $request)
{
// dd(\Crypt::encrypt('jtmccombs@gmail.com'));
try {
$email = \Crypt::decrypt($request->get('token'));
} catch (\Exception $e) {
return abort('403', 'Forbidden');
}
$user = User::whereEmail($email)->first();
if (!$user) {
return abort('403', 'Forbidden');
}
if (!$user->account) {
$b2bCompany = \DB::connection('mysql-b2b')->table('companies')->where('user_id', '=', $user->id)->first();
// $b2bCompany = false;
$accountName = $b2bCompany ? $b2bCompany->company_name : $user->email;
$account = new Account();
$account->ip = $request->getClientIp();
$account->name = $accountName;
$account->account_key = str_random(RANDOM_KEY_LENGTH);
$account->save();
$user->account_id = $account->id;
$user->registered = true;
$user->save();
$exists = \DB::connection('mysql')->table('users')->whereId($user->id)->count();
if (!$exists) {
\DB::connection('mysql')->table('users')->insert(['id' => $user->id, 'account_id' => $user->account_id, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at, 'deleted_at' => $user->deleted_at, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'phone' => $user->phone, 'username' => $user->username, 'email' => $user->email, 'password' => $user->password, 'confirmation_code' => $user->confirmation_code, 'registered' => $user->registered, 'confirmed' => $user->confirmed, 'notify_sent' => $user->notify_sent, 'notify_viewed' => $user->notify_viewed, 'notify_paid' => $user->notify_paid, 'public_id' => $user->public_id, 'force_pdfjs' => false, 'remember_token' => $user->remember_token, 'news_feed_id' => $user->news_feed_id, 'notify_approved' => $user->notify_approved, 'failed_logins' => $user->failed_logins, 'dark_mode' => $user->dark_mode, 'referral_code' => $user->referral_code]);
}
}
\Auth::loginUsingId($user->id);
return redirect('/');
}
示例3: createAccount
/**
* Create a new account instance after a valid registration.
*/
protected function createAccount(Request $request)
{
$account = new Account();
$account->email = $request->email;
$account->password = Hash::make($request->password);
$account->save();
return $account->id;
}
示例4: actionCreate
/**
* Creates a new Account model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Account();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例5: store
/**
* POST /api/accounts/{accounts}
* @param InsertAccountRequest $request
* @return Response
*/
public function store(InsertAccountRequest $request)
{
$account = new Account($request->only(['name']));
$account->user()->associate(Auth::user());
$account->save();
$account = $this->transform($this->createItem($account, new AccountTransformer()))['data'];
$pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID'));
$data = 'account created!';
$pusher->trigger('myChannel', 'accountCreated', $data);
return response($account, Response::HTTP_CREATED);
}
示例6: run
public function run()
{
$users = User::all();
foreach ($users as $user) {
foreach ($this->accounts as $account) {
$tmp = new Account(['name' => $account]);
$tmp->user()->associate($user);
$tmp->save();
}
}
}
示例7: actionCreate
/**
* Creates a new Account model.
* If creation is successful, the browser will be redirected to the 'index' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Account();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash("Account-success", Yii::t("app", "Account successfully created"));
return $this->redirect(['index']);
} else {
$currencyItems = Currency::find()->select(['id', 'name'])->where(['user_id' => Yii::$app->user->id])->asArray()->all();
$currencyItems = ArrayHelper::map($currencyItems, 'id', 'name');
return $this->render('create', ['model' => $model, 'currencyItems' => $currencyItems]);
}
}
示例8: it_can_delete_an_account
/**
* @test
* @return void
*/
public function it_can_delete_an_account()
{
$this->logInUser();
$name = 'echidna';
$account = new Account(compact('name'));
$account->user()->associate($this->user);
$account->save();
$response = $this->call('DELETE', '/api/accounts/' . $account->id);
$this->assertEquals(204, $response->getStatusCode());
$response = $this->call('DELETE', '/api/account/' . $account->id);
$this->assertEquals(404, $response->getStatusCode());
}
示例9: register
/**
* Register a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
//Check if the request has account and password
$validator = Validator::make($request->all(), ['account' => 'required|max:16', 'password' => 'required|max:20']);
//If it is lack of account and password
if ($validator->fails()) {
return response()->json(['status' => 404, 'message' => 'input error', 'data' => null]);
}
//Check if the account is existed
try {
$exist = Account::where('account', '=', $request->input('account'))->firstOrFail();
} catch (ModelNotFoundException $e) {
$account = $request->input('account');
$password = $request->input('password');
$name = $request->input('name', 'default_user');
$gender = $request->input('gender', 'unknown');
$nationality = $request->input('nationality', 'France');
$city = $request->input('city', 'Villejuif');
$address = $request->input('address', '');
//$hobby = $request->input('hobby','');
$nickName = $request->input('nickName', '');
$birthday = $request->input('birthday', '');
//store it to the database
$Account = new Account();
$Account->account = $account;
$Account->password = $password;
$Account->name = $name;
$Account->nickName = $nickName;
$Account->gender = $gender;
$Account->address = $address;
$Account->nationality = $nationality;
$Account->city = $city;
//$Account->hobby = $hobby;
$Account->birthday = $birthday;
$Account->save();
return response()->json(['status' => 0, 'message' => 'ok', 'data' => $Account->id]);
}
return response()->json(['status' => 403, 'message' => 'account existed', 'data' => null]);
}
示例10: getNinjaAccount
public function getNinjaAccount()
{
$account = Account::whereAccountKey(NINJA_ACCOUNT_KEY)->first();
if ($account) {
return $account;
} else {
$account = new Account();
$account->name = 'Invoice Ninja';
$account->work_email = 'contact@invoiceninja.com';
$account->work_phone = '(800) 763-1948';
$account->account_key = NINJA_ACCOUNT_KEY;
$account->save();
$random = str_random(RANDOM_KEY_LENGTH);
$user = new User();
$user->registered = true;
$user->confirmed = true;
$user->email = 'contact@invoiceninja.com';
$user->password = $random;
$user->username = $random;
$user->first_name = 'Invoice';
$user->last_name = 'Ninja';
$user->notify_sent = true;
$user->notify_paid = true;
$account->users()->save($user);
$accountGateway = new AccountGateway();
$accountGateway->user_id = $user->id;
$accountGateway->gateway_id = NINJA_GATEWAY_ID;
$accountGateway->public_id = 1;
$accountGateway->config = env(NINJA_GATEWAY_CONFIG);
$account->account_gateways()->save($accountGateway);
}
return $account;
}
示例11: actionRegister
public function actionRegister()
{
$user = new Account();
$model = new RegisterForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if (isset($_POST['save'])) {
$user->nickname = $model->nickname;
$user->password = $model->password;
$user->email = $model->email;
$user->save();
return $this->redirect(array('site/user', 'id' => $user->userID));
}
}
return $this->render('register', ['model' => $model]);
}
示例12: set_account
public function set_account()
{
try {
$account = new Account();
$account->user_id = auth()->user()->id;
$account->name = Request::input('name');
$account->type = Request::input('type');
$account->rate = Request::input('rate');
$account->balance = Request::input('balance');
$account->min_payment = Request::input('min_payment');
$account->save($account);
} catch (PDOException $e) {
die($e->getMessage());
}
}
示例13: savePost
/**
* save.
*
* @param Account $account account
* @param Request $input 输入
*/
public function savePost($account, $input)
{
$account->fill($input->all());
return $account->save();
}
示例14: saveAccount
private function saveAccount($user_id, $origin_msg, $openid, $date = '')
{
$date = $date ? $date : date("Y-m-d");
$comment = '';
$value = '';
$origin_msg = str_ireplace(',', ',', htmlspecialchars(strip_tags(trim($origin_msg))));
$origin_msg = preg_replace('/\\s/is', ',', $origin_msg);
$explode = explode(',', $origin_msg);
if (count($explode) == 2) {
list($comment, $value) = $explode;
}
if (is_numeric($value)) {
$account_model = new Account();
$account_model->user_id = $user_id;
$account_model->origin_msg = $origin_msg;
$account_model->date = $date;
$account_model->value = $value;
$account_model->comment = $comment;
// 收支类型
$account_model->io_type = $value >= 0 ? Account::IO_TYPE_EXPENDITURE : Account::IO_TYPE_INCOME;
$account_model->save();
$month_stat = $this->getMonthStat($user_id);
$result = ['success' => true, 'msg' => $account_model->comment . ':' . $account_model->value . "元" . "\r\n本月消费:" . $month_stat['sum'] . "\n计划 " . $month_stat['plan'] . " 的 " . round($month_stat['sum'] / $month_stat['plan'] * 100, 2) . "%" . "\r\n本月日均:" . $month_stat['average'] . "\n计划 " . round($month_stat['plan'] / 30, 2) . "\r\n回复“撤销”删除本次录入" . "\n<a href='" . Yii::$app->params['baseUrl'] . "my/index?openid=" . $openid . "'>查看详情</a>"];
} else {
if (stripos('撤销', $origin_msg) !== false) {
$account_model = Account::find()->where(['user_id' => $user_id])->orderBy(['id' => SORT_DESC])->one();
$account_model->delete();
$result = ['success' => true, 'msg' => "已删除上一条记录"];
} else {
$result = ['success' => false, 'msg' => "格式有误,请使用:\n吃饭,24"];
}
}
return $result;
}