本文整理汇总了PHP中Transfer::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Transfer::toArray方法的具体用法?PHP Transfer::toArray怎么用?PHP Transfer::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transfer
的用法示例。
在下文中一共展示了Transfer::toArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newTransfer
public function newTransfer()
{
$transfer = new Transfer();
$transfer->amount = floatval(Input::get('amount'));
$transfer->description = Input::get('description');
$transfer->fireflyuser_id = Auth::user()->id;
$transfer->date = Input::get('date');
// account_from (special)
if (!is_null(Input::get('account_from'))) {
$account = Auth::user()->accounts()->find(Input::get('account_from'));
if (!is_null($account)) {
$transfer->account_from = $account->id;
}
}
// account_to (special)
if (!is_null(Input::get('account_to'))) {
$account = Auth::user()->accounts()->find(Input::get('account_to'));
if (!is_null($account)) {
$transfer->account_to = $account->id;
}
}
// category (special)
if (strlen(Input::get('category')) > 0) {
$categories = Auth::user()->categories()->get();
//->where('name','=',Input::get('category'))->first();
$category = null;
foreach ($categories as $cat) {
if (Crypt::decrypt($cat->name) == Input::get('category')) {
$category = $cat;
break;
}
}
unset($cat, $categories);
if (is_null($category)) {
$category = new Category();
$category->fireflyuser_id = Auth::user()->id;
$category->name = Input::get('category');
$category->showtrend = 0;
$category->icon_id = Icon::first()->id;
$validator = Validator::make($category->toArray(), Category::$rules);
if ($validator->passes()) {
$category->name = Crypt::encrypt($category->name);
$category->save();
$transfer->category_id = $category->id;
}
} else {
$transfer->category_id = $category->id;
}
}
// budget (special)
if (intval(Input::get('budget')) > 0) {
$budget = Auth::user()->budgets()->find(intval(Input::get('budget')));
if (!is_null($budget)) {
$transfer->budget_id = $budget->id;
}
}
// target (special)
if (strlen(Input::get('target')) > 0) {
$targets = Auth::user()->targets()->get();
//->where('name','=',Input::get('category'))->first();
$target = null;
foreach ($targets as $t) {
if (Crypt::decrypt($t->description) == Input::get('target')) {
$transfer->target_id = $t->id;
break;
}
}
unset($targets, $t);
}
$validator = Validator::make($transfer->toArray(), Transfer::$rules);
$transfer->description = Crypt::encrypt($transfer->description);
if ($validator->fails()) {
return Redirect::to('/home/transfer/add')->withErrors($validator)->withInput();
} else {
$transfer->save();
return Redirect::to('/home');
}
}