%PDF- %PDF-
Direktori : /www/loslex/demo/app/Http/Controllers/ |
Current File : //www/loslex/demo/app/Http/Controllers/RangeController.php |
<?php namespace App\Http\Controllers; use Carbon\Carbon; use App\Models\Range; use App\Models\Contest; use Illuminate\View\View; use Illuminate\Http\Request; use Illuminate\Http\RedirectResponse; use Barryvdh\Debugbar\Facades\Debugbar; use App\Http\Requests\RangeUpdateRequest; class RangeController extends Controller { public function __construct() { $this->middleware('auth')->except(['index', 'show']); } public function index(): View { $ranges = Range::orderBy('name')->get(); return view('ranges.list', [ 'ranges' => $ranges, ]); } /* Display the specified resource. */ public function show(Range $range) : View { return view('ranges.show', [ 'range' => $range, 'contests' => Contest::where('range_id', $range->id) ->where('published', 1) ->where('date', '>=', Carbon::today()) ->orderBy('date') ->get() ]); } public function create(): View { $this->authorize('create', Range::class); return view('ranges.edit', ['range' => null]); } public function edit(Range $range): View { $this->authorize('update', Range::class); return view('ranges.edit', ['range' => $range]); } /* Store a newly created resource in storage. */ public function store(RangeUpdateRequest $request): RedirectResponse { $this->authorize('create', Contest::class); $range = new Range; $range->fill($request->validated()); $range->is_active = $request->boolean('is_active', false); $range->save(); return redirect(route('range.show', $range->id)); } /* Update the specified resource in storage. */ public function update(RangeUpdateRequest $request, Range $range): RedirectResponse { $this->authorize('update', $range); $validated = $request->validated(); $range->fill($validated); $range->is_active = $request->boolean('is_active', false); $range->setCoords($validated['location']); $range->save(); return redirect(route('range.show', $range->id)); } }