Url::query()->paginate(10) ]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('bo.pages.urls.create', [ 'brands' => Brand::all() ]); } /** * Store a newly created resource in storage. * * @param StoreUrlRequest $request * @return \Illuminate\Http\Response */ public function store(StoreUrlRequest $request) { $newUrl = new Url(); $newUrl->fill($request->validated()); $newUrl->brand()->associate($request->brand); $newUrl->saveOrFail(); return redirect()->route('bo.urls.index') ->with(['success' => 'L\'url pour la clé ' . $newUrl->key . ' a bien été créée.']); } /** * Show the form for editing the specified resource. * * @param Url $url * @return \Illuminate\Http\Response */ public function edit(Url $url) { return view('bo.pages.urls.edit', [ 'url' => $url, 'brands' => Brand::all() ]); } /** * Update the specified resource in storage. * * @param UpdateUrlRequest $request * @param Url $url * @return \Illuminate\Http\Response */ public function update(UpdateUrlRequest $request, Url $url) { $oldUrl = $url->value; ToolboxHelper::saveUrlHistory($url, $oldUrl); $url->fill($request->validated()); $url->brand()->associate($request->brand); $url->saveOrFail(); return redirect()->route('bo.urls.index') ->with(['success' => 'L\'url pour la clé ' . $url->key . ' a bien été modifiée.']); } /** * Remove the specified resource from storage. * * @param Url $url * @return \Illuminate\Http\Response */ public function destroy(Url $url) { foreach ($url->history as $history) { $history->deleteOrFail(); } foreach ($url->stats as $stats) { $stats->deleteOrFail(); } $url->deleteOrFail(); return redirect()->route('bo.urls.index') ->with(['warning' => 'L\'url pour la clé ' . $url->key . ' a bien été supprimée.']); } }