mirror of
https://github.com/prurigro/hypothetical.git
synced 2024-11-30 02:09:34 -05:00
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
|
<?php namespace App\Http\Controllers;
|
||
|
|
||
|
use Newsletter;
|
||
|
use App\Models\Subscriptions;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class SubscriptionController extends Controller
|
||
|
{
|
||
|
public function postSubscriptionSubmit(Request $request)
|
||
|
{
|
||
|
$this->validate($request, [
|
||
|
'name' => 'required',
|
||
|
'email' => 'required|email',
|
||
|
'address' => array('required', 'regex:/^([A-Za-z][0-9][A-Za-z] *[0-9][A-Za-z][0-9]|[0-9][0-9][0-9][0-9][0-9])$/')
|
||
|
]);
|
||
|
|
||
|
$name = $request['name'];
|
||
|
$fname = preg_replace('/ .*$/', '', $name);
|
||
|
$lname = preg_match('/. ./', $name) === 1 ? preg_replace('/^[^ ][^ ]* /', '', $name) : '';
|
||
|
$email = $request['email'];
|
||
|
$address = $request['address'];
|
||
|
|
||
|
// Submit the subscription request
|
||
|
Newsletter::subscribe($email, [
|
||
|
'FNAME' => $fname,
|
||
|
'LNAME' => $lname,
|
||
|
'ADDRESS' => $address
|
||
|
]);
|
||
|
|
||
|
// Save to the database on success
|
||
|
$subscriptions = new Subscriptions;
|
||
|
$subscriptions->name = $name;
|
||
|
$subscriptions->email = $email;
|
||
|
$subscriptions->location = $address;
|
||
|
$subscriptions->save();
|
||
|
|
||
|
return 'success';
|
||
|
}
|
||
|
}
|