Advertisement
fahimanzam

code_s

Apr 12th, 2020
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use App\Message;
  6. use Carbon\Carbon;
  7. use Illuminate\Http\Request;
  8.  
  9. class MessagesController extends Controller
  10. {
  11.     public function __construct()
  12.     {
  13.         $this->middleware('auth');
  14.     }
  15.  
  16.  
  17.     public function index() {
  18.         $messages = Message::latest()->paginate('5');
  19.  
  20.         return view('admin.message.index', compact('messages'));
  21.     }
  22.  
  23.  
  24.     public function sendMessage(Request $request) {
  25.         $request->validate([
  26.             'guest_name' => 'required',
  27.             'guest_email' => 'required',
  28.             'guest_subject' => 'required',
  29.             'guest_message' => 'required'
  30.         ]);
  31.  
  32.         Message::insert([
  33.             'guest_name' => $request->guest_name,
  34.             'guest_email' => $request->guest_email,
  35.             'guest_subject' => $request->guest_subject,
  36.             'guest_message' => $request->guest_message,
  37.             'created_at' => Carbon::now()
  38.         ]);
  39.  
  40.         return redirect('/contact#contact')->with('success', 'Thanks for your valueable thoughts.');
  41.      }
  42.  
  43.  
  44.      public function showMessage($id) {
  45.         $message = Message::find($id);
  46.  
  47.         return view('admin.message.show', compact('message'));
  48.      }
  49.  
  50.  
  51.      public function trashedMessage() {
  52.         $messages = Message::onlyTrashed()->paginate('5');
  53.        
  54.          return view('admin.message.trashed', compact('messages'));
  55.      }
  56.  
  57.  
  58.      public function restoreMessage($id) {
  59.         Message::withTrashed()->find($id)->restore();
  60.  
  61.         return redirect('/messages/trashed')->with('success', 'Message Restored Successfully.');
  62.      }
  63.  
  64.  
  65.      public function deleteMessage($id) {
  66.         Message::find($id)->delete();
  67.  
  68.         return redirect('/messages')->with('success', 'Message Successfully Moved to Trash.');
  69.      }
  70.  
  71.  
  72.      public function permaDelete($id) {
  73.         Message::withTrashed()->find($id)->forceDelete();
  74.  
  75.         return redirect('/messages/trashed')->with('deleted', 'Message Has Been Deleted Permanently.');
  76.      }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement