本文整理汇总了PHP中app\Project::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Project::firstOrCreate方法的具体用法?PHP Project::firstOrCreate怎么用?PHP Project::firstOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Project
的用法示例。
在下文中一共展示了Project::firstOrCreate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stestTasksCreated
public function stestTasksCreated()
{
$project = Project::firstOrCreate($this->projectdata);
$task = Task::create($this->taskdata);
$project->tasks()->save($task);
$user = User::firstOrFail();
$task->owner()->associate($user);
event(new TaskCreated($user, $project, $task));
$this->assertEquals(1, Task::count());
$this->assertEquals(TaskCreated::class, $task->feed->type);
$this->assertEquals($task->project->id, $task->feed->project_id);
$this->assertEquals(0, $task->comments->count());
$comment = Comment::create($this->commentdata);
$task->comments()->save($comment);
$this->assertEquals(1, $task->comments()->count());
}
示例2: getAutoHomeDetail
public function getAutoHomeDetail()
{
set_time_limit(0);
$snoopy = new Snoopy();
$datas = CarModel::whereBetween('id', [6500, 24000])->where('maintain_id', 0)->orderBy('id', 'asc')->get();
$hasMaintains = array();
//适配车型数组
foreach ($datas as $data) {
echo '------data_id------' . $data->id . '-START-';
if (!in_array($data->id, $hasMaintains)) {
$url = $data->url;
$snoopy->fetch($url);
$snoopy->results = mb_convert_encoding($snoopy->results, 'UTF-8', 'GBK');
//首保
preg_match('/首保:(\\d+?)公里\\/(\\d+?)个月\\s二保:(\\d+?)公里\\/(\\d+?)个月\\s+?间隔:(\\d+?)公里\\/(\\d+?)个月/', $snoopy->results, $match);
$maintain = new Detail();
if (isset($match[1])) {
$maintain->first_maintain_kilometers = $match[1];
}
if (isset($match[2])) {
$maintain->first_maintain_month = $match[2];
}
if (isset($match[3])) {
$maintain->second_maintain_kilometers = $match[3];
}
if (isset($match[4])) {
$maintain->second_maintain_month = $match[4];
}
if (isset($match[5])) {
$maintain->maintain_interval_kilometers = $match[5];
}
if (isset($match[6])) {
$maintain->maintain_interval_month = $match[6];
}
if ($maintain->save()) {
preg_match('/<tr><td><strong>保养项目\\/里程[\\s\\S]+(元)<\\/td>/', $snoopy->results, $match);
if (!isset($match[0])) {
continue;
} else {
$maintain_results = $match[0];
}
//project
preg_match_all('/<tr><td>(.*?)<\\/td>/', $maintain_results, $match);
$projects = $match[1];
//除去“保养项目/里程,前制动器,后制动器,总计”
array_shift($projects);
array_pop($projects);
array_pop($projects);
array_pop($projects);
$project_row_map = array_flip($projects);
//项目,价格信息入库
foreach ($projects as $project) {
$pro = Project::firstOrCreate(['name' => $project]);
preg_match('/<tr><td>' . $project . '<\\/td>[\\s]+<td>(\\d*)<\\/td>/', $maintain_results, $match);
if (isset($match[1]) && $match[1]) {
DetailProjectPrice::firstOrCreate(['detail_id' => $maintain->id, 'project_id' => $pro->id, 'price' => $match[1]]);
}
$row_project_id_map[$project_row_map[$project]] = $pro['id'];
}
//列数
preg_match('/保养项目\\/里程[\\s\\S]+?<tr><td>/', $maintain_results, $match);
preg_match_all('/(class="t_H3_item_bg")/', $match[0], $match);
$column = count($match[0]);
//行数
preg_match_all('/(<tr><td>)/', $maintain_results, $match);
$row = count($match[0]) - 4;
//section矩阵
for ($c = 0; $c < $column; $c++) {
$section = array();
for ($r = 0; $r < $row; $r++) {
$id = "c{$c}r{$r}";
preg_match('/' . $id . '"[\\s]+?>(.*?)<\\/td>/', $maintain_results, $match);
if (isset($match[1]) && !empty($match[1])) {
$section[] = $row_project_id_map[$r];
}
}
if (!empty($section)) {
$project_ids = implode(',', $section);
DetailSection::firstOrCreate(['detail_id' => $maintain->id, 'section' => $c, 'project_ids' => $project_ids]);
}
}
//保存
$data->maintain_id = $maintain->id;
$data->save();
preg_match('/id="specBox"[\\s\\S]+?<div/', $snoopy->results, $match);
if (isset($match[0]) && !empty($match[0])) {
$adaptMatch = $match[0];
preg_match_all('/<dd>(.+?)<\\/dd>/', $adaptMatch, $match);
if (isset($match[1]) && !empty($match[1])) {
//所有适用的车型
$model = CarModel::where('type_id', $data->type_id)->whereIn('name', $match[1]);
echo 1;
$model->update(['maintain_id' => $maintain->id]);
$ids = $model->lists('id');
// print_r($ids);die;
if (isset($ids) && !empty($ids)) {
$hasMaintains = empty($hasMaintains) ? $ids : array_merge($hasMaintains, $ids);
// print_r($hasMaintains);die;
}
}
//.........这里部分代码省略.........