3
0
Fork 0
This repository has been archived on 2024-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
ThemeParkPlus-Panel/app/Http/Controllers/Panel/MessageController.php

64 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2021-06-27 19:01:43 +00:00
<?php
namespace App\Http\Controllers\Panel;
use App\Http\Controllers\Controller;
use App\Message;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
class MessageController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['auth', 'verified', '2fa', 'admin']);
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('panel.message');
}
public function change(Request $request) {
$validator = Validator::make($request->all(), [
'message' => ['required', 'string']
]);
if(!$validator->passes()) {
session()->flash('error', 'Incorrect message');
return Redirect::back();
}
$message = Message::orderByDesc('id')->first();
if(!empty($message))
if($message->content === $request->get('message'))
return Redirect::back();
$message = Message::create([
'uuid' => Auth::user()->uuid,
'content' => $request->get('message')
]);
if(empty($message)) {
session()->flash('error', 'Unable to create message');
return Redirect::back();
}
session()->flash('success', 'Successfully posted message');
return Redirect::back();
}
}