Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Last active Mar 1, 2020
Embed
What would you like to do?
Creating reservation and sending mail example through the routes with JWT in OctoberCMS
Route::middleware(['api', 'jwt.auth'])->group(function () {
Route::post('create-reservation', function(Request $request) {
$reservation = new Reservation;
$reservation->pickup = $request->pickup;
$reservation->dropoff = $request->dropoff;
$reservation->user_id = $request->user_id;
$reservation->vehicle_id = $request->vehicle_id;
$reservation->save();
$user = \RainLab\User\Models\User::where('id', '=', $request->user_id)->first();
$vehicle = Vehicle::where('id', '=', $request->vehicle_id)->first();
$pickupParsed = Carbon::parse($request->pickup);
$dropoffParsed = Carbon::parse($request->dropoff);
$pickup = $pickupParsed->format('d.m.Y - h:m');
$dropoff = $dropoffParsed->format('d.m.Y - h:m');
$vars = [
'name' => $user->name,
'surname' => $user->surname,
'phone' => $user->phone,
'email' => $user->email,
'pickup' => $pickup,
'dropoff' => $dropoff,
'vehicle' => $vehicle->name
];
// User reservation Email
Mail::send('watchandlearn.vuerentapi::mail.reservation', $vars, function($message) use ($vars) {
$message->to($vars['email'], 'User name');
$message->subject('New Reservation');
});
// Admin reservation
Mail::send('watchandlearn.vuerentapi::mail.reservationadmin', $vars, function($message) {
$message->to('admins@email.com', 'Admin');
$message->subject('New Reservation');
});
return response()->json($vars);
});
Route::get('reservations/{id}', function($id) {
$user = \RainLab\User\Models\User::where('id', '=', $id)->with(['reservations'])->first();
$reservations = $user->reservations;
return $reservations;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment