Level 88
The last return will never be executed. Because when Calendar::create fails, it will throw an exception. So the only thing you can do is refactor your code for that
public function store(FormRequestCalendar $request)
{
$sanitized = $request->getSanitized();
try {
Calendar::create($sanitized))
return redirect()
->route('admin.calendars.index')
->with('success', 'Agenda criada com sucesso.');
} catch (\Exception $exception) {
return redirect()
->back()
->with('error', 'Ocorreu um erro ao criar a agenda.');
}
}
Now you have the try-catch you can provide incorrect information and it could break.
However, in most cases creating a calendar item should always work, because you have the FormRequestCalendar in place which validates the required fields for you. So I don't see the reason why you need to add the error case here?