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)
|
public function notify(Request $request, User $user)
|
||||||
{
|
{
|
||||||
$via = $request->validate([
|
$data = $request->validate([
|
||||||
"via" => "required|min:1|array",
|
"via" => "required|min:1|array",
|
||||||
"via.*" => "required|string|in:mail,database",
|
"via.*" => "required|string|in:mail,database",
|
||||||
])["via"];
|
"title" => "required|string|min:1",
|
||||||
|
"content" => "required|string|min:1"
|
||||||
|
]);
|
||||||
|
|
||||||
$mail = null;
|
$mail = null;
|
||||||
$database = null;
|
$database = null;
|
||||||
if (in_array('database', $via)) {
|
if (in_array('database', $data["via"])) {
|
||||||
$database = $request->validate([
|
$database = [
|
||||||
"title" => "required|string|min:1",
|
"title" => $data["title"],
|
||||||
"content" => "required|string|min:1"
|
"content" => $data["content"]
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
if (in_array('mail', $via)) {
|
if (in_array('mail', $data["via"])) {
|
||||||
$data = $request->validate([
|
$mail = (new MailMessage)
|
||||||
"subject" => "required|string|min:1",
|
->subject($data["title"])
|
||||||
"body" => "required|string|min:1"
|
->line(new HtmlString($data["content"]));
|
||||||
]);
|
|
||||||
$mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"]));
|
|
||||||
}
|
}
|
||||||
$user->notify(
|
$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!');
|
return redirect()->route('admin.users.notifications', $user->id)->with('success', 'User notified!');
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,24 +61,24 @@ class NotificationController extends Controller
|
||||||
$discordUser = DiscordUser::find($userId);
|
$discordUser = DiscordUser::find($userId);
|
||||||
$user = $discordUser ? $discordUser->user : User::findOrFail($userId);
|
$user = $discordUser ? $discordUser->user : User::findOrFail($userId);
|
||||||
|
|
||||||
$via = $request->validate([
|
$data = $request->validate([
|
||||||
"via" => ["required", new Delimited("in:mail,database")]
|
"via" => ["required", new Delimited("in:mail,database")],
|
||||||
|
"title" => "required|string|min:1",
|
||||||
|
"content" => "required|string|min:1"
|
||||||
]);
|
]);
|
||||||
$via = explode(',', $via["via"]);
|
$via = explode(',', $data["via"]);
|
||||||
$mail = null;
|
$mail = null;
|
||||||
$database = null;
|
$database = null;
|
||||||
if (in_array('database', $via)) {
|
if (in_array('database', $via)) {
|
||||||
$database = $request->validate([
|
$database = [
|
||||||
"title" => "required|string|min:1",
|
"title" => $data["title"],
|
||||||
"content" => "required|string|min:1"
|
"content" => $data["content"]
|
||||||
]);
|
];
|
||||||
}
|
}
|
||||||
if (in_array('mail', $via)) {
|
if (in_array('mail', $via)) {
|
||||||
$data = $request->validate([
|
$mail = (new MailMessage)
|
||||||
"subject" => "required|string|min:1",
|
->subject($data["title"])
|
||||||
"body" => "required|string|min:1"
|
->line(new HtmlString($data["content"]));
|
||||||
]);
|
|
||||||
$mail = (new MailMessage)->subject($data["subject"])->line(new HtmlString($data["body"]));
|
|
||||||
}
|
}
|
||||||
$user->notify(
|
$user->notify(
|
||||||
new DynamicNotification($via, $database, $mail)
|
new DynamicNotification($via, $database, $mail)
|
||||||
|
|
|
@ -36,13 +36,11 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Send via</label><br>
|
<label>Send via</label><br>
|
||||||
<input value="database" id="database" name="via[]"
|
<input value="database" id="database" name="via[]"
|
||||||
type="checkbox"
|
type="checkbox">
|
||||||
onchange="toggleGroup('database-group')">
|
|
||||||
<label for="database">Database</label>
|
<label for="database">Database</label>
|
||||||
<br>
|
<br>
|
||||||
<input value="mail" id="mail" name="via[]"
|
<input value="mail" id="mail" name="via[]"
|
||||||
type="checkbox"
|
type="checkbox">
|
||||||
onchange="toggleGroup('mail-group')">
|
|
||||||
<label for="mail">Mail</label>
|
<label for="mail">Mail</label>
|
||||||
@error('via')
|
@error('via')
|
||||||
<div class="invalid-feedback d-block">
|
<div class="invalid-feedback d-block">
|
||||||
|
@ -51,61 +49,30 @@
|
||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-none" id="database-group">
|
<div class="form-group" >
|
||||||
<div class="form-group" >
|
<label for="title">Title</label>
|
||||||
<label for="title">Title</label>
|
<input value="{{old('title')}}" id="title" name="title"
|
||||||
<input value="{{old('title')}}" id="title" name="title"
|
type="text"
|
||||||
type="text"
|
class="form-control @error('title') is-invalid @enderror">
|
||||||
class="form-control @error('title') is-invalid @enderror">
|
@error('title')
|
||||||
@error('title')
|
<div class="invalid-feedback">
|
||||||
<div class="invalid-feedback">
|
{{$message}}
|
||||||
{{$message}}
|
|
||||||
</div>
|
|
||||||
@enderror
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="content">Content</label>
|
|
||||||
<textarea id="content"
|
|
||||||
name="content"
|
|
||||||
type="content"
|
|
||||||
class="form-control @error('content') is-invalid @enderror">
|
|
||||||
{{old('content')}}
|
|
||||||
</textarea>
|
|
||||||
@error('content')
|
|
||||||
<div class="text-danger">
|
|
||||||
{{$message}}
|
|
||||||
</div>
|
|
||||||
@enderror
|
|
||||||
</div>
|
</div>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
<div class="d-none" id="mail-group">
|
<label for="content">Content</label>
|
||||||
<div class="form-group">
|
<textarea id="content"
|
||||||
<label for="subject">Subject</label>
|
name="content"
|
||||||
<input value="{{old('subject')}}" id="subject" name="subject"
|
type="content"
|
||||||
type="text"
|
class="form-control @error('content') is-invalid @enderror">
|
||||||
class="form-control @error('subject') is-invalid @enderror">
|
{{old('content')}}
|
||||||
@error('subject')
|
</textarea>
|
||||||
<div class="invalid-feedback">
|
@error('content')
|
||||||
{{$message}}
|
<div class="text-danger">
|
||||||
</div>
|
{{$message}}
|
||||||
@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>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group text-right">
|
<div class="form-group text-right">
|
||||||
<button type="submit" class="btn btn-primary">Submit</button>
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
@ -122,20 +89,6 @@
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', (event) => {
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
// Summernote
|
// 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({
|
$('#content').summernote({
|
||||||
height: 100,
|
height: 100,
|
||||||
toolbar: [
|
toolbar: [
|
||||||
|
|
Loading…
Reference in a new issue