本文整理匯總了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");
}