本文整理汇总了PHP中Contract::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Contract::firstOrCreate方法的具体用法?PHP Contract::firstOrCreate怎么用?PHP Contract::firstOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contract
的用法示例。
在下文中一共展示了Contract::firstOrCreate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createContract
public function createContract($loan_id)
{
// Find the profile of the person who's id matches the id of the person currently logged in. Find it in DB.
$profile = UserProfile::where('id', '=', Auth::user()->id)->first();
try {
$loan = LoanApp::findOrFail($loan_id);
} catch (Exception $e) {
return Redirect::route('mytransaction')->with('message', "Could not load loan: " . $e->getMessage());
}
$lenders = $this->getLenders($loan_id);
if (empty($lenders)) {
return Redirect::route('mytransaction')->with('message', 'Could not find lenders for this loan request');
}
$contract = Contract::firstOrCreate(array('offer_id' => Input::get('offer_id', $loan_id)));
if ($contract->getAttribute('status') === 'complete') {
return Redirect::to('previewContract/' . $loan_id);
}
// todo: set these using the form
$contract->setAttribute('start_date', date('d/m/Y'));
$contract->setAttribute('end_date', date('d/m/Y'));
if (Request::isMethod('post')) {
// Check if actually posting data.
$save = $contract->fill(Input::all())->save();
$errors = Session::pull('messages', array());
if ($save === false && empty($errors)) {
$errors[] = 'Failed to save contract';
}
if (empty($errors)) {
return Redirect::to('previewContract/' . $loan_id);
}
}
$prepayment_rules = array("There are no penalties for paying off the loan early.", "Borrower must pay 5% of the original loan amount.", "Borrower must pay the complete interest of the loan.", "Borrower must pay \$100");
return View::make('createContract', compact('loan', 'lenders', 'profile', 'errors', 'contract', 'prepayment_rules'));
}