I'm trying to create all-day event with MS Graph API. The issue I'm having is when I create event on outlook it extends the event to the next day, screenshot below:
This is the event body I'm sending:
this is how I'm calculating start and end day:
$eventBody['start'] = array("dateTime" => date('Y-m-d H:i:s', strtotime($row->day_date)), "timeZone" => $timeZone);
$eventBody['end'] = array("dateTime" => date('Y-m-d H:i:s', strtotime($row->day_date . ' +1 day')), "timeZone" => $timeZone);
Related
I'm trying to get all the reservations in a specific date and time and count the guests to find the available seats
What i'm doing in the controller:
public function getSeats() {
$data = request()->validate([
'date' => 'required',
'hours' => 'required',
'place_id' => 'required'
]);
$hours = [];
foreach($data['hours'] as $h) {
$date = $data['date'].' '.$h;
//Carbon date: 2021-08-31 08:00:00 | Database Date: 2021-08-31 08:00:00
$count = Reservation::where('place_id', $data['place_id'])->whereDate('date', Carbon::create($date)->toDateTimeString())->sum('guests');
$object = (object) [
'hour' => $h,
'guests' => $count
];
array_push($hours, $object);
}
}
It returns null, what am i doing wrong?
**Edit
I'm also using 24H in the time selector, so when i create a reservation at 12:00 in the morning eloquent grabs it as 00:00 in the night.
Using where instead of whereDate fixed the issue
I am using laravel admin, and I am trying to send emails at a specific time. I pass this datetime data into the first argument of later method
"date" => Carbon #1576722840 {#543 ▼
date: 2019-12-19 02:34:00.0 UTC (+00:00) }
However, it doesnt work as I expected. it randomly sends emails.
$form->saved(function (Form $form) {
if ($form->model()->to === '4') {
$emails = EmailAddress::all();
} else {
$emails = EmailAddress::where('user_type', $form->model()->to)->get();
}
$data = ['id' => $form->model()->id, 'title' => $form->model()->title, 'from' => $form->model()->from, 'body' => $form->model()->body, 'date' => $form->model()->schedule_date, 'is_html' => $form->model()->is_html];
foreach ($emails as $email) {
$url = URL::signedRoute('unsubscribe',['email_address_id' => $email->id]);
Mail::to($email)->later($data['date'],new MagazineMail($data,$url));
}
});
return $form;
}
As I understood it, if I want to send a mail at a specific time, I should just pass a datetime into the first argement, so I have no idea why my code does not work.
I made sure my env file is correct and set QUEUE_CONNECTION=database.
Well, I want to send an automated email every Friday using MailChimp/Mandrill.
Email Template :
Hi {{firstName}},
You weekly weekend pass is {{code}}.
Here, My email content is dynamically generated. So, before sending automated email, there should be some mechanism where I call the rest api from where I get the firstName and code. Then email is sent to different user.
{
[{
firstName: 'test',
code: 'Xewetwerx'
},
{
firstName: 'test2',
code: 'Xewetwrtd'
}]
}
I know we can write code in our backend server and call the API every Friday using cronjob(to send an email every Friday) but I don't want to use any cronjob.
Is it possible to make API call and send automated mail using MailChimp or mandrill ???
Outcome:
2 email should be sent with different code.
Mandrill implements scheduled emails through the sent_at parameter.
It's possible to send an email using a template and specify date and time when the message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. If you specify a time in the past, the message will be sent immediately. Note that for the sent_at feature you will need a paid (non free) account
If you choose PHP as the programming language for your backend,
you can use the official PHP API library.
example: (the code is not tested and could contain errors)
require_once '/path/to/MailchimpTransactional/vendor/autoload.php';
$mailchimp = new MailchimpTransactional\ApiClient();
$mailchimp->setApiKey('YOUR_API_KEY');
$msg = array(
'subject' => 'My subject',
'from_email' => 'ellery#example.com',
'to' => array(array('email' => 'recipient1#example.com', 'name' => 'Recipient 1'),array('email' => 'recipient2#example.com', 'name' => 'Recipient 2')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#example.com',
'vars' =>
array(
array(
'name' => 'firstName',
'content' => 'test'),
array(
'name' => 'code',
'content' => 'Xewetwerx')
)),
array(
'rcpt' => 'recipient2#example.com',
'vars' =>
array(
array(
'name' => 'firstName',
'content' => 'test2'),
array(
'name' => 'code',
'content' => 'Xewetwrtd')
))));
$response = $mailchimp->messages->sendTemplate([
"template_name" => "template_name",
"template_content" => [[]],
"message" => $msg,
"send_at" => "2021-06-23 09:05:00" ,
]);
print_r($response);
Working on a Laravel application whereby am working on the backend validation of two dates. The 2 dates are mainly departureDate and returnDate respectively.
On the departure date am trying to validate it to be required, should be of type date and should be a date after today. On the return date I am also trying to implement a validation logic whereby return date should be 3 days or more after departure date but it should be less than 180 days after departure date.
Validate function
public function validateDates(Request $request){
//dd($request->all());
$now = new \DateTime();
$after_date = $now->parse($this->departureDate)->addDays(3);
$maxdays = $now->parse($this->departureDate)->addDays(180);
$validation = $this->validate($request, [
'departureDate' => 'required|date|after:now',
'returnDate' => 'required|date_format:"Y-m-d"|after:' . $after_date->toDateString().'|before:' . $maxdays->toDateString()
],
[
'departureDate.after' => 'Your departure date should be tomorrow or any date in the future',
'returnDate.after' => 'Your return date should be 3 or more days after the departure date',
'returnDate.before' => 'Your return date should be no more than 180 days from the departure date',
]
};
I think your logic is fine. You are, however, probably looking to use Carbon instead. It has the parse() method you are looking for. Also addDays() and toDateString().
So, on top of your file, add the following statement:
use Carbon\Carbon;
and then change your validateDate() method to this one:
public function validateDates(Request $request)
{
$after_date = Carbon::parse($this->departureDate)->addDays(3)->toDateString();
$max_days = Carbon::parse($this->departureDate)->addDays(180)->toDateString();
$validation = $this->validate($request,
[
'departureDate' => 'required|date|after:now',
'returnDate' => 'required|date_format:"Y-m-d"|after:' . $after_date . '|before:' . $max_days
],
[
'departureDate.after' => 'Your departure date should be tomorrow or any date in the future',
'returnDate.after' => 'Your return date should be 3 or more days after the departure date',
'returnDate.before' => 'Your return date should be no more than 180 days from the departure date',
]
);
};
I am assuming that you have your departureDate defined somewhere and hence you are using $this->departureDate, but if it's coming from your request instead, you should change that to $request->departureDate for example.
I am trying to charge a one time fee + first month subscription fee in stripe but I can't figure out how to do it since they change their interface.
After the initial fee + first month subscription fee, it should roll on a monthly basis.
Ideally I am looking to do this with Laravel Cashier.
Any ideas and examples will be welcome.
Here is how to charge a subscription or a one time pay in stripe:
public function index()
{
if (!request()->wantsJson()) {
abort(404);
}
$plan = request()->get('plan');
$stripeToken = request()->get('stripeToken');
$user = User::findOrFail(request()->get('userId'));
if (is_null($user) || is_null($plan) || is_null($stripeToken)) {
return response()->json(403);
}
if ($plan === self::PREMIUM) {
$user->newSubscription('main', self::PREMIUM_ID)->create($stripeToken);
}
if ($plan === self::EXTENDED) {
$transaction = $user->charge(999, ['currency' => 'usd', 'source' => $stripeToken]);
$payment = new Payment([
'payment_id' => $transaction->id,
'payment_status' => $transaction->paid,
'amount' => $transaction->amount,
]);
$user->payments()->save($payment);
}
return response()->json(200);
}
$user->newSubscription('main', 'plan_xxxxxxxxxxxxxx')->create($request->stripeToken);
$customer = Customer::retrieve($parent_account->stripe_id);
$charge = Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'gbp',
'description' => 'Joining Fee',
));