本文整理汇总了PHP中app\Contact::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Contact::firstOrCreate方法的具体用法?PHP Contact::firstOrCreate怎么用?PHP Contact::firstOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Contact
的用法示例。
在下文中一共展示了Contact::firstOrCreate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeContacts
public function storeContacts($campaign_id, Request $request)
{
set_time_limit(0);
$date = \Carbon\Carbon::parse($request->input('dateTime'))->toDateTimeString();
$file = $request->file('file');
$campaign = Campaign::find($campaign_id);
$contacts = [];
$results = \Excel::selectSheetsByIndex(0)->load($file, function ($reader) use($campaign) {
$reader->ignoreEmpty();
$reader->each(function ($row) use($campaign) {
if (isset($row['email']) && $row['email']) {
$email = $row['email'];
$email = trim($email);
if (!$this->checkEmail($email)) {
return false;
}
$contact = Contact::firstOrCreate(['email' => $email, 'client_id' => $campaign->client->id]);
if (isset($row['first_name'])) {
$contact->first_name = $row['first_name'];
}
if (isset($row['last_name'])) {
$contact->last_name = $row['last_name'];
}
if (isset($row['company'])) {
$contact->company = $row['company'];
}
if (isset($row['title'])) {
$contact->title = $row['title'];
}
if (isset($row['address'])) {
$contact->address = trim(str_replace("\n", ' ', $row['address']));
}
if (isset($row['city'])) {
$contact->city = $row['city'];
}
if (isset($row['state'])) {
$contact->state = $row['state'];
}
if (isset($row['zip'])) {
$contact->zip = $row['zip'];
}
$contact->save();
if (!$contact->bounced && !$contact->unsubscribe) {
array_push($this->contacts, $contact->id);
}
}
});
});
$contactCount = 0;
foreach ($this->contacts as $contact) {
if (!$campaign->contacts->contains($contact)) {
$campaign->contacts()->attach($contact);
$contactCount++;
}
}
return redirect()->route('admin.campaigns.show', $campaign->id)->with('message', "{$contactCount} contacts added to Campaign");
}
示例2: store
public function store($touch_id, Request $request)
{
$date = \Carbon\Carbon::now()->toDateTimeString();
$emails = explode(',', $request->input('email'));
$count = 0;
foreach ($emails as $email) {
$email = trim($email);
if (!$this->checkEmail($email)) {
continue;
}
$touch = Touch::find($touch_id);
$contact = Contact::firstOrCreate(['email' => $email, 'client_id' => $touch->campaign->client->id]);
if ($contact->unsubscribe || $contact->bounced) {
return redirect()->back()->with('message', "{$contact->email} is unreachable or has unsubscribed");
}
$email = Email::create(['subject' => $touch->subject, 'reply_to' => $touch->campaign->client->reply_to, 'from' => $touch->campaign->client->reply_to, 'send_on' => $date, 'template' => "emails.{$touch->template}", 'draft' => false, 'trackable' => false, 'campaign_id' => $touch->campaign->id, 'contact_id' => $contact->id, 'touch_id' => $touch->id]);
$email->salted_id = bcrypt($email->id);
$email->save();
$count++;
}
return redirect()->back()->with('message', "{$count} test emails sent");
}
示例3: signupForward
public function signupForward(Request $request)
{
$email = $request->input('email');
if (!$this->checkEmail($email)) {
return redirect()->back()->withInput()->with('error', "{$email} is not a valid email");
}
$campaign = Campaign::find($request->input('campaign_id'));
$touch = $campaign->touchs()->first();
$date = \Carbon\Carbon::now()->toDateTimeString();
$contact = Contact::firstOrCreate(['email' => $email, 'client_id' => $touch->campaign->client->id]);
if ($contact->unsubscribe || $contact->bounced) {
return redirect()->back()->with('message', "{$contact->email} is unreachable or has unsubscribed");
}
$newEmail = Email::create(['subject' => $touch->subject, 'reply_to' => $touch->campaign->client->reply_to, 'from' => $touch->campaign->client->reply_to, 'send_on' => $date, 'template' => "emails.{$touch->template}", 'draft' => false, 'trackable' => false, 'campaign_id' => $touch->campaign->id, 'contact_id' => $contact->id, 'touch_id' => $touch->id]);
$newEmail->salted_id = bcrypt($newEmail->id);
$newEmail->save();
return redirect()->back()->with('message', "We will contact {$email} right away");
}