new Entry(), 'section' => $section, 'words' => FormHelpers::getEntryFormWords($section), 'isEdit' => false, 'oldModifications' => old( 'modifications', [] ), 'oldLanguages' => old( 'languages', [] ), 'oldFilesArray' => $this->services->prepareOldFiles( null ) ]; if( $data['words'] === [] ) abort(500); if( section_must_be( 'romhacks', $section ) ){ $data['modifications'] = Modification::orderBy('name')->get(); } if( section_must_be( [ 'romhacks', 'translations', 'homebrew' ], $section ) ){ $data['statuses'] = Status::orderBy('id')->get(); } return view('submissions.create', $data); } public function edit(Request $request, string $section, Entry $entry){ if( $entry->type !== $section ) abort(404); $data = [ 'entry' => $entry, 'section' => $section, 'words' => FormHelpers::getEntryFormWords($section), 'isEdit' => true, 'oldModifications' => old('modifications', $entry->modifications->pluck('id')->toArray() ?? [] ), 'oldLanguages' => old('languages', $entry->languages->pluck('id')->toArray() ?? [] ), 'oldFilesArray' => $this->services->prepareOldFiles( $entry ) ]; if( $data['words'] === [] ) abort(500); if( section_must_be( 'romhacks', $section ) ){ $data['modifications'] = Modification::orderBy('name')->get(); } if( section_must_be( [ 'romhacks', 'translations' ], $section ) ){ $data['statuses'] = Status::orderBy('id')->get(); } return view('submissions.edit', $data); } public function destroy(Request $request, string $section, Entry $entry) { if( $entry->type !== $section ) abort(404); if( $entry->comments_thread_id) DeleteXenForoCommentsThread::dispatch( $entry->comments_thread_id ); $entry->delete(); return redirect( route('entries.index') )->with('success', "Entry successfully deleted."); } public function store(Request $request, string $section){ $request = $request->input('submit-state') === 'draft' ? app(StoreDraftRequest::class) : app(StoreEntryRequest::class); $request->validateResolved(); try { $entry = $this->services->storeEntry($request, $section); return match ($entry->state) { 'published' => redirect()->route('entries.show', ['section' => $section, 'entry' => $entry->slug])->with('success', "Your entry has been published."), 'pending' => redirect()->route('home')->with('success', "Your entry has been submitted and is pending review."), default => redirect()->route('home')->with('success', "Your entry has been saved as a draft.") }; } catch ( SubmissionException $e ) { return back()->withInput()->withErrors(['error' => $e->getMessage()]); } catch ( \Exception $e ) { return back()->withInput()->withErrors(['error' => 'Unknown error: '.$e->getMessage()]); } } public function update(Request $request, string $section, Entry $entry) { $request = $request->input('submit-state') === 'draft' ? app(StoreDraftRequest::class) : app(StoreEntryRequest::class); $request->validateResolved(); try { $entry = $this->services->editEntry($request, $section, $entry); return match ($entry->state) { 'published' => redirect()->route('entries.show', ['section' => $section, 'entry' => $entry->slug])->with('success', "Your entry has been published."), 'pending' => redirect()->route('home')->with('success', "Your entry has been submitted and is pending review."), default => redirect()->route('home')->with('success', "Your entry has been saved as a draft.") }; } catch ( SubmissionException $e ) { return back()->withInput()->withErrors(['error' => $e->getMessage()]); } catch ( \Exception $e ) { return back()->withInput()->withErrors(['error' => 'Unknown error: '.$e->getMessage()]); } } }