Merge database and mail fields
This commit is contained in:
parent
0597b4aabe
commit
a19cbb1575
|
@ -167,28 +167,28 @@ class UserController extends Controller
|
|||
*/
|
||||
public function notify(Request $request, User $user)
|
||||
{
|
||||
$via = $request->validate([
|
||||
$data = $request->validate([
|
||||
"via" => "required|min:1|array",
|
||||
"via.*" => "required|string|in:mail,database",
|
||||
])["via"];
|
||||
|
||||
$mail = null;
|
||||
$database = null;
|
||||
if (in_array('database', $via)) {
|
||||
$database = $request->validate([
|
||||
"title" => "required|string|min:1",
|
||||
"content" => "required|string|min:1"
|
||||
]);
|
||||
|
||||
$mail = null;
|
||||
$database = null;
|
||||
if (in_array('database', $data["via"])) {
|
||||
$database = [
|
||||
"title" => $data["title"],
|
||||
"content" => $data["content"]
|
||||
];
|
||||
}
|
||||
if (in_array('mail', $via)) {
|
||||
$data = $request->validate([
|
||||
"subject" => "required|string|min:1",
|
||||
"body" => "required|string|min:1"
|
||||
]);
|
||||
$mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"]));
|
||||
if (in_array('mail', $data["via"])) {
|
||||
$mail = (new MailMessage)
|
||||
->subject($data["title"])
|
||||
->line(new HtmlString($data["content"]));
|
||||
}
|
||||
$user->notify(
|
||||
new DynamicNotification($via, $database, $mail)
|
||||
new DynamicNotification($data["via"], $database, $mail)
|
||||
);
|
||||
return redirect()->route('admin.users.notifications', $user->id)->with('success', 'User notified!');
|
||||
}
|
||||
|
|
|
@ -61,24 +61,24 @@ class NotificationController extends Controller
|
|||
$discordUser = DiscordUser::find($userId);
|
||||
$user = $discordUser ? $discordUser->user : User::findOrFail($userId);
|
||||
|
||||
$via = $request->validate([
|
||||
"via" => ["required", new Delimited("in:mail,database")]
|
||||
]);
|
||||
$via = explode(',', $via["via"]);
|
||||
$mail = null;
|
||||
$database = null;
|
||||
if (in_array('database', $via)) {
|
||||
$database = $request->validate([
|
||||
$data = $request->validate([
|
||||
"via" => ["required", new Delimited("in:mail,database")],
|
||||
"title" => "required|string|min:1",
|
||||
"content" => "required|string|min:1"
|
||||
]);
|
||||
$via = explode(',', $data["via"]);
|
||||
$mail = null;
|
||||
$database = null;
|
||||
if (in_array('database', $via)) {
|
||||
$database = [
|
||||
"title" => $data["title"],
|
||||
"content" => $data["content"]
|
||||
];
|
||||
}
|
||||
if (in_array('mail', $via)) {
|
||||
$data = $request->validate([
|
||||
"subject" => "required|string|min:1",
|
||||
"body" => "required|string|min:1"
|
||||
]);
|
||||
$mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"]));
|
||||
$mail = (new MailMessage)
|
||||
->subject($data["title"])
|
||||
->line(new HtmlString($data["content"]));
|
||||
}
|
||||
$user->notify(
|
||||
new DynamicNotification($via, $database, $mail)
|
||||
|
|
|
@ -36,13 +36,11 @@
|
|||
<div class="form-group">
|
||||
<label>Send via</label><br>
|
||||
<input value="database" id="database" name="via[]"
|
||||
type="checkbox"
|
||||
onchange="toggleGroup('database-group')">
|
||||
type="checkbox">
|
||||
<label for="database">Database</label>
|
||||
<br>
|
||||
<input value="mail" id="mail" name="via[]"
|
||||
type="checkbox"
|
||||
onchange="toggleGroup('mail-group')">
|
||||
type="checkbox">
|
||||
<label for="mail">Mail</label>
|
||||
@error('via')
|
||||
<div class="invalid-feedback d-block">
|
||||
|
@ -51,7 +49,6 @@
|
|||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="d-none" id="database-group">
|
||||
<div class="form-group" >
|
||||
<label for="title">Title</label>
|
||||
<input value="{{old('title')}}" id="title" name="title"
|
||||
|
@ -77,36 +74,6 @@
|
|||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-none" id="mail-group">
|
||||
<div class="form-group">
|
||||
<label for="subject">Subject</label>
|
||||
<input value="{{old('subject')}}" id="subject" name="subject"
|
||||
type="text"
|
||||
class="form-control @error('subject') is-invalid @enderror">
|
||||
@error('subject')
|
||||
<div class="invalid-feedback">
|
||||
{{$message}}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="body">Body</label>
|
||||
<textarea id="body"
|
||||
name="body"
|
||||
type="body"
|
||||
class="form-control @error('body') is-invalid @enderror">
|
||||
{{old('body')}}
|
||||
</textarea>
|
||||
@error('body')
|
||||
<div class="text-danger">
|
||||
{{$message}}
|
||||
</div>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group text-right">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
|
@ -122,20 +89,6 @@
|
|||
<script>
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
// Summernote
|
||||
$('#body').summernote({
|
||||
height: 100,
|
||||
toolbar: [
|
||||
[ 'style', [ 'style' ] ],
|
||||
[ 'font', [ 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear'] ],
|
||||
[ 'fontname', [ 'fontname' ] ],
|
||||
[ 'fontsize', [ 'fontsize' ] ],
|
||||
[ 'color', [ 'color' ] ],
|
||||
[ 'para', [ 'ol', 'ul', 'paragraph', 'height' ] ],
|
||||
[ 'table', [ 'table' ] ],
|
||||
[ 'insert', [ 'link'] ],
|
||||
[ 'view', [ 'undo', 'redo', 'fullscreen', 'codeview', 'help' ] ]
|
||||
]
|
||||
})
|
||||
$('#content').summernote({
|
||||
height: 100,
|
||||
toolbar: [
|
||||
|
|
Loading…
Reference in a new issue