. */ namespace App\Commands; use App\Models\ShowSong; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; class CreateShowSongCommand extends CommandBase { /** @var ShowSong */ private $_songName; public function __construct($songName) { $this->_songName = $songName; } /** * @return bool */ public function authorize() { return Gate::allows('create-show-song'); } /** * @throws \Exception * @return CommandResponse */ public function execute() { $slug = Str::slug($this->_songName); $rules = [ 'title' => 'required|unique:show_songs,title,NULL,id,deleted_at,NULL|max:250', 'slug' => 'required|unique:show_songs,slug,NULL,id,deleted_at,NULL', ]; $validator = Validator::make([ 'title' => $this->_songName, 'slug' => $slug, ], $rules); if ($validator->fails()) { return CommandResponse::fail($validator); } ShowSong::create([ 'title' => $this->_songName, 'slug' => $slug, 'lyrics' => '', ]); return CommandResponse::succeed(['message' => 'Song created!']); } }