Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use App\Message;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- class MessagesController extends Controller
- {
- public function __construct()
- {
- $this->middleware('auth');
- }
- public function index() {
- $messages = Message::latest()->paginate('5');
- return view('admin.message.index', compact('messages'));
- }
- public function sendMessage(Request $request) {
- $request->validate([
- 'guest_name' => 'required',
- 'guest_email' => 'required',
- 'guest_subject' => 'required',
- 'guest_message' => 'required'
- ]);
- Message::insert([
- 'guest_name' => $request->guest_name,
- 'guest_email' => $request->guest_email,
- 'guest_subject' => $request->guest_subject,
- 'guest_message' => $request->guest_message,
- 'created_at' => Carbon::now()
- ]);
- return redirect('/contact#contact')->with('success', 'Thanks for your valueable thoughts.');
- }
- public function showMessage($id) {
- $message = Message::find($id);
- return view('admin.message.show', compact('message'));
- }
- public function trashedMessage() {
- $messages = Message::onlyTrashed()->paginate('5');
- return view('admin.message.trashed', compact('messages'));
- }
- public function restoreMessage($id) {
- Message::withTrashed()->find($id)->restore();
- return redirect('/messages/trashed')->with('success', 'Message Restored Successfully.');
- }
- public function deleteMessage($id) {
- Message::find($id)->delete();
- return redirect('/messages')->with('success', 'Message Successfully Moved to Trash.');
- }
- public function permaDelete($id) {
- Message::withTrashed()->find($id)->forceDelete();
- return redirect('/messages/trashed')->with('deleted', 'Message Has Been Deleted Permanently.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement