%PDF- %PDF-
Direktori : /data/www_bck/loslex_bck/demo/app/Http/Controllers/ |
Current File : //data/www_bck/loslex_bck/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::select('id', 'name', 'coords', 'region')->orderBy('name')->get(); $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()) ->limit(5)->get() ]); } public function create(): View { $this->authorize('crate', Range::class); return view('ranges.edit'); } 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)); } }