这对你有帮助
class MailChimpController extends Controller
{
public function add( Request $request ) {
$apikey="api key-us17";
$server = "us17.";
$listid = 'list id';
if ( $request->isMethod( 'post' ) ) {
//try {
$request_data = $request->all();
$email =$request_data['email'];
$request_data['earlyprice'] = isset($request_data['earlyprice']) ? floatval($request_data['earlyprice']) : 0.0 ;
$request->merge(['earlyprice' => $request_data['earlyprice']]);
$request_data['gaprice'] = isset($request_data['gaprice']) ? floatval($request_data['gaprice']) : 0.0 ;
$request->merge(['gaprice' => $request_data['gaprice']]);
$this->validate( $request, [
'title' => 'required|max:255',
'location' => 'required|max:255',
'starttime' => 'required',
'category' => 'required',
'type' => 'required',
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:min_width=360,min_height=261',
'description' => 'required|max:1000',
'fullname' => 'required|max:255',
'phone' => 'required|max:255',
'email' => 'required|max:255',
'website' => 'required',
'socialmedia' => 'required'
] );
$event = new \App\CustomerEvent();
$imageName = "";
if ( $request->hasFile( 'image' ) ) {
$imageName = md5( time() ) . '.' . $request->image->getClientOriginalExtension();
$request->image->move( public_path( 'events_images' ), $imageName );
}
$requestData = $request->all();
$requestData['image'] = $imageName;
$requestData['status'] = "D";
$requestData['eventkey'] = $this->generate_key();
$event->fill( $requestData );
$x = $event->save();
$auth = base64_encode( 'user:'.$apikey );
$data = array(
'apikey' => $apikey,
'email_address' => $email,
'status' => 'subscribed',
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'Pathto ur trigger');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/json','Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
//return redirect()->back()->with( 'status', 'Event created' );
} else {
return view( 'events.host.index' );
}
}