. */ namespace Poniverse\Ponyfm\Commands; use Gate; use Poniverse\Ponyfm\Models\Announcement; use Validator; class CreateAnnouncementCommand extends CommandBase { /** @var Announcement */ private $_announcementName; public function __construct($announcementName) { $this->_announcementName = $announcementName; } /** * @return bool */ public function authorize() { return Gate::allows('create-announcement'); } /** * @throws \Exception * @return CommandResponse */ public function execute() { $rules = [ 'name' => 'required|max:50', ]; $validator = Validator::make([ 'name' => $this->_announcementName, ], $rules); if ($validator->fails()) { return CommandResponse::fail($validator); } Announcement::create([ 'title' => $this->_announcementName, ]); return CommandResponse::succeed(['message' => 'Announcement created!']); } }