Add customer contact inquiry system, automated receipt emails, admin communication inbox, and customer profile management
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Communication;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -25,7 +26,13 @@ class AccountController extends Controller
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return view('account.index', compact('user', 'orders'));
|
||||
$communications = Communication::where('user_id', $user->id)
|
||||
->orWhere('email', strtolower($user->email))
|
||||
->with('replies')
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return view('account.index', compact('user', 'orders', 'communications'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\ContactInquiryReplyMail;
|
||||
use App\Models\Communication;
|
||||
use App\Models\CommunicationReply;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CommunicationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of all customer communications / inquiries.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$query = Communication::with(['user', 'order', 'replies'])->latest();
|
||||
|
||||
// Status filter
|
||||
if ($request->filled('status') && $request->input('status') !== 'all') {
|
||||
$query->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
// Search query
|
||||
if ($request->filled('q')) {
|
||||
$search = trim($request->input('q'));
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%")
|
||||
->orWhere('subject', 'like', "%{$search}%")
|
||||
->orWhere('message', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$communications = $query->paginate(20)->withQueryString();
|
||||
|
||||
$counts = [
|
||||
'all' => Communication::count(),
|
||||
'new' => Communication::where('status', 'new')->count(),
|
||||
'in_progress' => Communication::where('status', 'in_progress')->count(),
|
||||
'resolved' => Communication::where('status', 'resolved')->count(),
|
||||
'closed' => Communication::where('status', 'closed')->count(),
|
||||
];
|
||||
|
||||
return view('admin.communications.index', [
|
||||
'communications' => $communications,
|
||||
'counts' => $counts,
|
||||
'currentStatus' => $request->input('status', 'all'),
|
||||
'search' => $request->input('q', ''),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified communication thread.
|
||||
*/
|
||||
public function show(Communication $communication): View
|
||||
{
|
||||
$communication->load(['user.orders', 'order.items', 'replies.user']);
|
||||
|
||||
// Mark as in_progress if still new when viewed by admin
|
||||
if ($communication->status === 'new') {
|
||||
$communication->update(['status' => 'in_progress']);
|
||||
}
|
||||
|
||||
return view('admin.communications.show', [
|
||||
'communication' => $communication,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status and/or admin notes for this communication.
|
||||
*/
|
||||
public function updateStatus(Request $request, Communication $communication): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'status' => 'required|string|in:new,in_progress,resolved,closed',
|
||||
'admin_notes' => 'nullable|string|max:5000',
|
||||
]);
|
||||
|
||||
$communication->update($validated);
|
||||
|
||||
return back()->with('success', 'Status van het bericht is bijgewerkt.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reply to the customer from the admin dashboard.
|
||||
*/
|
||||
public function sendReply(Request $request, Communication $communication): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'message' => 'required|string|min:5|max:5000',
|
||||
], [
|
||||
'message.required' => 'Vul alstublieft een antwoordbericht in.',
|
||||
'message.min' => 'Het antwoordbericht moet minimaal 5 tekens bevatten.',
|
||||
]);
|
||||
|
||||
$reply = CommunicationReply::create([
|
||||
'communication_id' => $communication->id,
|
||||
'user_id' => Auth::id(),
|
||||
'is_admin_reply' => true,
|
||||
'message' => trim($validated['message']),
|
||||
]);
|
||||
|
||||
$communication->update([
|
||||
'status' => 'resolved',
|
||||
'last_replied_at' => now(),
|
||||
]);
|
||||
|
||||
// Send email to customer from info@jouwdriedee.nl
|
||||
try {
|
||||
Mail::to($communication->email)->send(new ContactInquiryReplyMail($communication, $reply));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Fout bij verzenden van admin reactie naar klant: '.$e->getMessage(), [
|
||||
'communication_id' => $communication->id,
|
||||
'email' => $communication->email,
|
||||
]);
|
||||
|
||||
return back()->with('warning', 'Het antwoord is opgeslagen in de database, maar er trad een fout op bij het verzenden van de e-mail: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return back()->with('success', 'Jouw antwoord is verzonden naar '.$communication->email.' en toegevoegd aan het communicatiedossier.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified communication from storage.
|
||||
*/
|
||||
public function destroy(Communication $communication): RedirectResponse
|
||||
{
|
||||
$communication->delete();
|
||||
|
||||
return redirect()->route('admin.communications.index')->with('success', 'Klantbericht is verwijderd.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Communication;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of registered customers and guest buyers.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$search = trim($request->input('q', ''));
|
||||
|
||||
// Query registered non-admin users
|
||||
$usersQuery = User::where('is_admin', false);
|
||||
if ($search !== '') {
|
||||
$usersQuery->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
$registeredUsers = $usersQuery->withCount(['orders', 'communications'])->latest()->get();
|
||||
|
||||
// Also discover guest customers who placed orders or sent inquiries without an account
|
||||
$registeredEmails = User::pluck('email')->map(fn ($e) => strtolower($e))->toArray();
|
||||
|
||||
$guestOrderEmails = Order::whereNull('user_id')
|
||||
->select('customer_email', 'customer_name', 'customer_phone', 'created_at')
|
||||
->latest()
|
||||
->get()
|
||||
->groupBy(fn ($item) => strtolower($item->customer_email));
|
||||
|
||||
$guestInquiryEmails = Communication::whereNull('user_id')
|
||||
->select('email', 'name', 'phone', 'created_at')
|
||||
->latest()
|
||||
->get()
|
||||
->groupBy(fn ($item) => strtolower($item->email));
|
||||
|
||||
$guestCustomers = collect();
|
||||
$allGuestEmails = $guestOrderEmails->keys()->merge($guestInquiryEmails->keys())->unique();
|
||||
|
||||
foreach ($allGuestEmails as $email) {
|
||||
if (in_array(strtolower($email), $registeredEmails)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($search !== '' && ! str_contains(strtolower($email), strtolower($search))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$orderGroup = $guestOrderEmails->get($email, collect());
|
||||
$inquiryGroup = $guestInquiryEmails->get($email, collect());
|
||||
|
||||
$latestOrder = $orderGroup->first();
|
||||
$latestInquiry = $inquiryGroup->first();
|
||||
|
||||
$name = $latestOrder ? $latestOrder->customer_name : ($latestInquiry ? $latestInquiry->name : 'Gast');
|
||||
$phone = $latestOrder ? $latestOrder->customer_phone : ($latestInquiry ? $latestInquiry->phone : null);
|
||||
$createdAt = $latestOrder ? $latestOrder->created_at : ($latestInquiry ? $latestInquiry->created_at : now());
|
||||
|
||||
$guestCustomers->push((object) [
|
||||
'id' => null,
|
||||
'is_registered' => false,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'phone' => $phone,
|
||||
'orders_count' => $orderGroup->count(),
|
||||
'communications_count' => $inquiryGroup->count(),
|
||||
'created_at' => $createdAt,
|
||||
]);
|
||||
}
|
||||
|
||||
// Map registered users into unified customer object
|
||||
$registeredCustomers = $registeredUsers->map(function ($u) {
|
||||
return (object) [
|
||||
'id' => $u->id,
|
||||
'is_registered' => true,
|
||||
'name' => $u->name,
|
||||
'email' => $u->email,
|
||||
'phone' => null,
|
||||
'orders_count' => $u->orders_count,
|
||||
'communications_count' => $u->communications_count,
|
||||
'created_at' => $u->created_at,
|
||||
];
|
||||
});
|
||||
|
||||
$allCustomers = $registeredCustomers->concat($guestCustomers)->sortByDesc('created_at')->values();
|
||||
|
||||
// Manual pagination for the unified list
|
||||
$perPage = 20;
|
||||
$page = LengthAwarePaginator::resolveCurrentPage('page');
|
||||
$paginatedCustomers = new LengthAwarePaginator(
|
||||
$allCustomers->forPage($page, $perPage),
|
||||
$allCustomers->count(),
|
||||
$perPage,
|
||||
$page,
|
||||
['path' => route('admin.customers.index'), 'query' => $request->query()]
|
||||
);
|
||||
|
||||
return view('admin.customers.index', [
|
||||
'customers' => $paginatedCustomers,
|
||||
'totalRegistered' => $registeredUsers->count(),
|
||||
'totalGuests' => $guestCustomers->count(),
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a specific customer's profile, including their full communication dossier and orders.
|
||||
*/
|
||||
public function show(string $identifier): View
|
||||
{
|
||||
$user = null;
|
||||
$email = null;
|
||||
|
||||
if (is_numeric($identifier)) {
|
||||
$user = User::find($identifier);
|
||||
if ($user) {
|
||||
$email = strtolower($user->email);
|
||||
}
|
||||
} else {
|
||||
$email = strtolower(urldecode($identifier));
|
||||
$user = User::where('email', $email)->first();
|
||||
}
|
||||
|
||||
if (! $user && ! $email) {
|
||||
abort(404, 'Klant niet gevonden.');
|
||||
}
|
||||
|
||||
// Fetch all communications for this customer (by user_id OR by email)
|
||||
$communicationsQuery = Communication::with(['replies', 'order'])->latest();
|
||||
if ($user) {
|
||||
$communicationsQuery->where(function ($q) use ($user, $email) {
|
||||
$q->where('user_id', $user->id)
|
||||
->orWhere('email', $email);
|
||||
});
|
||||
} else {
|
||||
$communicationsQuery->where('email', $email);
|
||||
}
|
||||
$communications = $communicationsQuery->get();
|
||||
|
||||
// Fetch all orders for this customer (by user_id OR by email)
|
||||
$ordersQuery = Order::with('items')->latest();
|
||||
if ($user) {
|
||||
$ordersQuery->where(function ($q) use ($user, $email) {
|
||||
$q->where('user_id', $user->id)
|
||||
->orWhere('customer_email', $email);
|
||||
});
|
||||
} else {
|
||||
$ordersQuery->where('customer_email', $email);
|
||||
}
|
||||
$orders = $ordersQuery->get();
|
||||
|
||||
$customerName = $user ? $user->name : ($orders->first()?->customer_name ?? $communications->first()?->name ?? 'Klant');
|
||||
$customerPhone = $orders->first()?->customer_phone ?? $communications->first()?->phone ?? null;
|
||||
$totalSpent = $orders->sum('total');
|
||||
|
||||
return view('admin.customers.show', [
|
||||
'user' => $user,
|
||||
'email' => $email,
|
||||
'customerName' => $customerName,
|
||||
'customerPhone' => $customerPhone,
|
||||
'totalSpent' => $totalSpent,
|
||||
'communications' => $communications,
|
||||
'orders' => $orders,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\ContactInquiryConfirmationMail;
|
||||
use App\Mail\ContactInquiryReceivedMail;
|
||||
use App\Models\Communication;
|
||||
use App\Models\Order;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the contact / question form.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$user = Auth::user();
|
||||
$userOrders = $user ? $user->orders()->latest()->take(10)->get() : collect();
|
||||
|
||||
return view('contact.index', [
|
||||
'user' => $user,
|
||||
'userOrders' => $userOrders,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the submission of a question / contact inquiry.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:150',
|
||||
'email' => 'required|email|max:150',
|
||||
'phone' => 'nullable|string|max:40',
|
||||
'subject' => 'required|string|max:200',
|
||||
'order_number' => 'nullable|string|max:50',
|
||||
'message' => 'required|string|min:10|max:5000',
|
||||
], [
|
||||
'name.required' => 'Vul alstublieft jouw naam in.',
|
||||
'email.required' => 'Vul alstublieft een geldig e-mailadres in.',
|
||||
'email.email' => 'Het ingevoerde e-mailadres is niet geldig.',
|
||||
'subject.required' => 'Vul alstublieft het onderwerp van jouw vraag in.',
|
||||
'message.required' => 'Vul alstublieft jouw bericht of vraag in.',
|
||||
'message.min' => 'Het bericht moet minimaal 10 tekens bevatten.',
|
||||
]);
|
||||
|
||||
$orderId = null;
|
||||
if (! empty($validated['order_number'])) {
|
||||
$cleanNumber = ltrim(trim($validated['order_number']), '#');
|
||||
$foundOrder = Order::where('order_number', $cleanNumber)->first();
|
||||
if ($foundOrder) {
|
||||
$orderId = $foundOrder->id;
|
||||
}
|
||||
}
|
||||
|
||||
$communication = Communication::create([
|
||||
'user_id' => Auth::id(),
|
||||
'order_id' => $orderId,
|
||||
'name' => trim($validated['name']),
|
||||
'email' => strtolower(trim($validated['email'])),
|
||||
'phone' => ! empty($validated['phone']) ? trim($validated['phone']) : null,
|
||||
'subject' => trim($validated['subject']),
|
||||
'message' => trim($validated['message']),
|
||||
'status' => 'new',
|
||||
'ip_address' => $request->ip(),
|
||||
'user_agent' => substr((string) $request->userAgent(), 0, 500),
|
||||
]);
|
||||
|
||||
// 1. Send incoming mail to webshop management (info@jouwdrieedee.nl / info@jouwdriedee.nl)
|
||||
try {
|
||||
$shopInbox = Setting::get('contact_email', 'info@jouwdrieedee.nl');
|
||||
// Ensure delivery to both info@jouwdrieedee.nl and fallback info@jouwdriedee.nl
|
||||
$recipients = array_unique([$shopInbox, 'info@jouwdrieedee.nl', 'info@jouwdriedee.nl']);
|
||||
Mail::to($recipients)->send(new ContactInquiryReceivedMail($communication));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Fout bij versturen van klantvraag naar webshop beheer: '.$e->getMessage(), [
|
||||
'communication_id' => $communication->id,
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Send afschrift receipt from (noreply@jouwdriedee.nl) to the customer
|
||||
try {
|
||||
Mail::to($communication->email)->send(new ContactInquiryConfirmationMail($communication));
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Fout bij versturen van afschrift naar klant: '.$e->getMessage(), [
|
||||
'communication_id' => $communication->id,
|
||||
'email' => $communication->email,
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('contact.index')->with(
|
||||
'success',
|
||||
'Bedankt voor je vraag! We hebben jouw bericht ontvangen. Er is een afschrift verzonden naar '.$communication->email.'.'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Communication;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ContactInquiryConfirmationMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Communication $communication) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('noreply@jouwdriedee.nl', 'Jouwdriedee.nl'),
|
||||
subject: 'Afschrift: Jouw vraag aan Jouwdriedee.nl - '.$this->communication->subject,
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.contact-inquiry-confirmation',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Communication;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ContactInquiryReceivedMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(public Communication $communication) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '[Nieuwe Klantvraag] #'.$this->communication->id.': '.$this->communication->subject,
|
||||
replyTo: [
|
||||
new Address($this->communication->email, $this->communication->name),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.contact-inquiry-received',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Communication;
|
||||
use App\Models\CommunicationReply;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ContactInquiryReplyMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Communication $communication,
|
||||
public CommunicationReply $reply
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('info@jouwdriedee.nl', 'Jouwdriedee.nl Klantenservice'),
|
||||
replyTo: [
|
||||
new Address('info@jouwdriedee.nl', 'Jouwdriedee.nl Klantenservice'),
|
||||
],
|
||||
subject: 'Reactie op jouw vraag: '.$this->communication->subject.' - Jouwdriedee.nl',
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
view: 'emails.contact-inquiry-reply',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Communication extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'order_id',
|
||||
'name',
|
||||
'email',
|
||||
'phone',
|
||||
'subject',
|
||||
'message',
|
||||
'status',
|
||||
'admin_notes',
|
||||
'ip_address',
|
||||
'user_agent',
|
||||
'last_replied_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_replied_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function order(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function replies(): HasMany
|
||||
{
|
||||
return $this->hasMany(CommunicationReply::class)->oldest();
|
||||
}
|
||||
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'new' => 'Nieuw',
|
||||
'in_progress' => 'In behandeling',
|
||||
'resolved' => 'Beantwoord',
|
||||
'closed' => 'Gesloten',
|
||||
default => ucfirst($this->status),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CommunicationReply extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'communication_id',
|
||||
'user_id',
|
||||
'is_admin_reply',
|
||||
'message',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_admin_reply' => 'boolean',
|
||||
];
|
||||
|
||||
public function communication(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Communication::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -48,4 +48,14 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Communications / questions submitted by this user.
|
||||
*
|
||||
* @return HasMany<Communication, $this>
|
||||
*/
|
||||
public function communications(): HasMany
|
||||
{
|
||||
return $this->hasMany(Communication::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user