当前位置: 首页>>代码示例>>PHP>>正文


PHP Record::where方法代码示例

本文整理汇总了PHP中Record::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Record::where方法的具体用法?PHP Record::where怎么用?PHP Record::where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Record的用法示例。


在下文中一共展示了Record::where方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 public function run()
 {
     $faker = Faker::create();
     $word = array('trials', 'rebills', 'dp', 'returned');
     foreach (range(1, 5) as $index) {
         $digit = $faker->numberBetween($min = 0, $max = 3);
         $amount = Record::where(function ($query) use($index) {
             $query->where('product_id', $index);
         })->sum('amount');
         $product = Product::create(['name' => $faker->word, 'product_id' => $index, "site_link" => $faker->word, 'description' => $faker->paragraph(1), "price_per_bottle" => $faker->word, "manufacturer" => $faker->firstNameMale, "inhouse" => $amount]);
     }
 }
开发者ID:hunt-son,项目名称:inventory-app-2,代码行数:12,代码来源:ProductsTableSeeder.php

示例2: store

 /**
  * Store a newly created record in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (Input::all() != null) {
         $validator = Validator::make($data = Input::all(), Record::$rules);
         if ($validator->fails()) {
             return Redirect::back()->withErrors($validator)->withInput();
         }
     }
     $data['amount'] = (int) $data['amount'];
     $data['product_id'] = (int) $data['product_id'];
     if ($data['action'] == 'trials' or $data['action'] == 'rebills' or $data['action'] == 'dp') {
         $data['amount'] = -1 * $data['amount'];
     }
     $product = Product::where('product_id', Input::get('product_id'))->first();
     $product_id = $data['product_id'];
     $inhouse = $product->inhouse = Record::where(function ($query) use($product_id, $data) {
         $query->where('product_id', $product_id);
         $query->where('action', $data['action']);
     })->sum('amount') + $data['amount'];
     $data['authorization'] = Auth::user()->username;
     Record::create($data);
     $positive_values = Record::where(function ($query) use($product_id) {
         $query->where('product_id', $product_id);
         $query->where('action', 'trials')->orWhere('action', 'rebills')->orWhere('action', 'dps');
     })->sum('amount');
     $negative_values = Record::where(function ($query) use($product_id) {
         $query->where('product_id', $product_id);
         $query->where('action', 'returned');
     })->sum('amount');
     if ($data['action'] != 'received') {
         $total_sold = -$data['amount'] + $positive_values - $negative_values;
     } else {
         $total_sold = 0;
     }
     $fourty_five_day_average = Record::where(function ($query) use($product_id) {
         $query->where('updated_at', '>=', Carbon\Carbon::now()->subdays(45));
         $query->where('product_id', $product_id);
     })->avg('amount');
     if ($fourty_five_day_average != 0) {
         $daysleft = $inhouse / $fourty_five_day_average;
     } else {
         $daysleft = 0;
     }
     //actually average over 6 weeks
     $average_this_week = number_format(Record::where(function ($query) use($product_id) {
         $query->where('product_id', $product_id);
         $query->where('created_at', '>=', Carbon\Carbon::now()->subWeeks(6));
     })->avg('amount'), 2);
     //actually the same as average_this_week (for now)
     $average_last_week = number_format(Record::where(function ($query) use($product_id) {
         $query->where('product_id', $product_id);
         $query->where('created_at', '>=', Carbon\Carbon::now()->subWeeks(6));
     })->avg('amount'), 2);
     $one_week_change = 0;
     if ($average_this_week != 0) {
         $one_week_change = ($average_this_week - $average_last_week) * 100 / $average_this_week;
     }
     if ($total_sold != 0) {
         Product::where("product_id", $product_id)->update(array("inhouse" => $inhouse, "daysleft" => $daysleft, "weekly_average" => $fourty_five_day_average, "change" => $one_week_change, "total_sold" => $total_sold));
     } else {
         Product::where("product_id", $product_id)->update(array("inhouse" => $inhouse, "daysleft" => $daysleft, "weekly_average" => $fourty_five_day_average, "change" => $one_week_change));
     }
     $today = Carbon\carbon::today()->toFormattedDateString();
     $daily = [];
     $daily["inhouse"] = $inhouse;
     $daily[$data['action']] = $data['amount'];
     $daily['today'] = $today;
     $daily['product_id'] = $data['product_id'];
     $dailyRecord = Daily::where(function ($query) use($product_id, $today) {
         $query->where('product_id', $product_id);
         $query->where('today', '==', $today);
     });
     if ($dailyRecord->exists()) {
         $dailyRecord->update(array("inhouse" => $inhouse, $data['action'] => $data['amount'], 'today' => $today, 'product_id' => $product_id));
     } else {
         Daily::create($daily);
     }
     return Redirect::route('daily.index');
 }
开发者ID:hunt-son,项目名称:inventory-app-2,代码行数:84,代码来源:RecordsController.php

示例3: use

    $query->where('updated_at', '>=', Carbon\Carbon::now()->subdays(45));
})->avg('amount');
if ($fourty_five_day_average != 0) {
    $product_days_til_empty = $products->inhouse / $fourty_five_day_average;
} else {
    $product_days_til_empty = 0;
}
$product_past_three_weeks = Record::where(function ($query) use($product_id) {
    $query->where('product_id', $product_id);
    $query->where('updated_at', '>=', Carbon\Carbon::now()->subweeks(3));
})->avg('amount');
$three_week_product_average = 0;
for ($three_weeks = Carbon\Carbon::now()->subWeeks(21); $three_weeks->lte(Carbon\Carbon::now()); $three_weeks->addWeeks(3)) {
    $thisAverage = Record::where(function ($query) use($product_id, $three_weeks) {
        $query->where('product_id', $product_id);
        $query->where('updated_at', '<=', $three_weeks->addWeeks(3));
        $three_weeks->subWeeks(3);
        $query->where('updated_at', '>=', $three_weeks);
    })->avg('amount');
    $three_week_product_average = $thisAverage + $three_week_product_average;
}
array_push($three_week_average, $three_week_product_average);
array_push($past_three_weeks, $product_past_three_weeks);
array_push($days_til_empty, $product_days_til_empty);
?>


@extends('layouts.base')

@section('body')

开发者ID:hunt-son,项目名称:inventory-app-2,代码行数:30,代码来源:edit.blade.php

示例4: destroy

 /**
  * Remove the specified dashboard from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (Product::where('id', $id)->delete() == true) {
         Record::where("id", $id)->delete();
         Daily::where("id", $id)->delete();
         Flash::success('You have deleted a product!');
         return "success";
     } else {
         return "failure";
     }
 }
开发者ID:hunt-son,项目名称:inventory-app-2,代码行数:17,代码来源:DashboardsController.php

示例5: destroy

 /**
  * Remove the specified product from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Product::where('id', $id)->forceDelete();
     Record::where('id', $id)->forceDelete();
     Daily::where('id', $id)->forceDelete();
     Flash::success('this product has been permanently removed from the inventory database');
     return 'success';
 }
开发者ID:hunt-son,项目名称:inventory-app-2,代码行数:14,代码来源:ProductsController.php


注:本文中的Record::where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。