So I am creating a project that will allow my users to send a booking confirmation, booking reminder, and booking cancellation email to their clients. This is how I was planning to set it up:
BookingConfirmationController.php
namespace App\Http\Controllers\Sessions;
use App\Session;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class BookingConfirmationController extends Controller
{
public function sendBookingConfirmation(Request $request, Session $session)
{
$getClient = $session->client()->first();
//send the mail to the client here
$session->booking_confirmation_sent = true;
$session->save();
return redirect()->back();
}
public function sendBookingReminder(Request $request, Session $session)
{
$getClient = $session->client()->first();
//send the mail to the client here
$session->booking_reminder_sent = true;
$session->save();
return redirect()->back();
}
public function sendBookingCancellation(Request $request, Session $session)
{
$getClient = $session->client()->first();
//send the mail to the client here
$session->booking_cancellation_sent = true;
$session->save();
return redirect()->back();
}
}
Routes
Route::post('/session/{session}/send/bookingconfirmation', 'Sessions\BookingConfirmationController@sendBookingConfirmation')->name('confirmation.booking');
Route::post('/session/{session}/send/bookingreminder', 'Sessions\BookingConfirmationController@sendBookingReminder')->name('reminder.booking');
Route::post('/session/{session}/send/bookingcancellation', 'Sessions\BookingConfirmationController@sendBookingCancellation')->name('cancellation.booking');
Should I go this route or should I create a controller for each of these methods and go the RESTful route? Just looking for input on what the most efficient way would be and why. Thanks.
Hi,
I would probably opt to create models for BookingConfirmation
, BookingReminder
and BookingCancellation
, which I would be creating in the controller using REST.
My main goal would be that I would have a trace of what confirmations/reminders/cancellation notices that were sent to the customer. If you want to make it more generic, you could create a model BookingNotification
and assign a type to it.
The dispatching of mails I would probably write in a event listener on the created
event of that model; if you have one model, you could just add a case to send one of the three mails. I know I'm a bit fanatic when it comes to tracing and audit trails, but I like to be able to check when these notifications were triggered (and by what user), and this would achieve just that.
Also - why are you putting this in a namespace <...>/Sessions
- as a new developer on your project, I would probably not immediately start looking into that namespace :-)
I hope this helps - there is no right or wrong here, but this is how I would go around this.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community