本文整理汇总了PHP中app\models\Customer::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::findOrFail方法的具体用法?PHP Customer::findOrFail怎么用?PHP Customer::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Customer
的用法示例。
在下文中一共展示了Customer::findOrFail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editForm
public function editForm(Request $request, $id){
$customer = Customer::findOrFail($id);
if($customer){
$data = [
'customer' => $customer,
'subnav' => $this->default_sub_nav
];
return view('customers.edit', $data);
}
return redirect('/customers')->flash('error', 'Customer not found');
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$project = Project::find($id);
if (!$project) {
return response()->json('Le projet n\'existe pas.', 404);
}
$validator = Validator::make($request->all(), ['status' => 'in:draft,accepted,pending,refused,command,billing', 'quotation_price' => 'integer', 'quotation_date' => 'date', 'customer_id' => 'integer']);
if ($validator->fails()) {
return response()->json($validator->errors()->all(), 400);
}
if ($request->input('customer_id')) {
try {
$customer = Customer::findOrFail($request->input('customer_id'));
} catch (Exception $e) {
return response()->json('Le client n\'existe pas.', 404);
}
}
$project->update($request->all());
return $project;
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update($id, Request $request)
{
$this->validate($request, ['CUSTNAME' => 'required']);
$customer = Customer::findOrFail($id);
$customer->update($request->all());
Session::flash('flash_message', 'Customer updated!');
return redirect('customers');
}
示例4: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
$customer = Customer::findOrFail($id)->delete();
// redirect
Session::flash('message', 'Successfully deleted the customer!');
return redirect('admin/customers');
}
示例5: lowerList
public function lowerList(Request $request)
{
$customer_id = $request->input('customer_id');
$customer = Customer::findOrFail($customer_id);
// $lower_list = Customer::with(['yikangQuestionnaire', 'orders'])->where('referrer_id', $customer->id);
// $lower_list = \DB::table('customers')
// ->leftJoin('yikang_questionnaires', 'customers.id', '=', 'yikang_questionnaires.customer_id')
// ->leftJoin('orders', 'customers.id', '=', 'orders.customer_id')
// ->where('customers.referrer_id', $customer->id)
// ->select('customers.*', 'orders.*');
$lower_list = \DB::select(\DB::raw('
SELECT tmp1.*, tmp2.* FROM
(
SELECT
lowers.*, yikang_questionnaires.id as questionnaire_id, yikang_questionnaires.q1, yikang_questionnaires.q1b, yikang_questionnaires.q2, yikang_questionnaires.q2b, yikang_questionnaires.q3, yikang_questionnaires.q3a, yikang_questionnaires.q3b, yikang_questionnaires.q3c, yikang_questionnaires.q3d, yikang_questionnaires.q3d2, yikang_questionnaires.q3e, yikang_questionnaires.q4
FROM
(SELECT * FROM customers WHERE referrer_id = ' . $customer->id . ') lowers
LEFT JOIN
yikang_questionnaires
ON lowers.id = yikang_questionnaires.customer_id
) tmp1
LEFT JOIN
(
SELECT
customer_id, sum(cash_payment) as lower_cash_payment_sum, sum(beans_payment) as lower_beans_payment_sum
FROM
orders
WHERE
customer_id IN (SELECT id FROM customers WHERE referrer_id = ' . $customer->id . ')
GROUP BY
customer_id
) tmp2
ON
tmp1.id = tmp2.customer_id
'));
return response()->json(['success' => true, 'data' => ['lower_list' => $lower_list]]);
}