本文整理汇总了PHP中Record::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Record::create方法的具体用法?PHP Record::create怎么用?PHP Record::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Record
的用法示例。
在下文中一共展示了Record::create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 50) as $index) {
$number = rand(1, 5);
$product = Product::find($number);
Record::create(["name" => $product->name, "action" => "trials", "status" => "comes_in", "authorization" => $faker->firstNameFemale, "amount" => 5 + $index * 5, "product_id" => $number]);
}
}
示例2: create_one
public static function create_one($model)
{
$model = Record::allow($model, ['email', 'password', 'auth']);
$model['password'] = crypt($model['password'], SALT);
return parent::create($model);
}
示例3: createRecord
private function createRecord($i)
{
$user = Record::create(['value' => 'value_' . $i]);
}
示例4: 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');
}
示例5: create
public static function create($key_value_pairs)
{
$key_value_pairs['date'] = gmdate('Y-m-d');
return parent::create($key_value_pairs);
}