From d5691453f708ff5a288daeec21a00a19e888ca40 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 8 Nov 2020 12:55:49 +0100 Subject: Go back to previous news page... --- app/Http/Controllers/NewsController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php index 8be535e..8ea2000 100644 --- a/app/Http/Controllers/NewsController.php +++ b/app/Http/Controllers/NewsController.php @@ -7,6 +7,8 @@ use function dd; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\Session; +use Illuminate\Support\Facades\URL; use App\Models\Post; @@ -21,6 +23,7 @@ class NewsController extends Controller { $news = Post::orderBy('created_at', 'desc')->paginate(6); + Session::flash('prev-url', URL::full()); //$data = ['news' => $news]; //return view('pages.news')->with($data); //return view('pages.news')->with('news', $news); @@ -91,6 +94,7 @@ class NewsController extends Controller public function edit($id) { $data = Post::findOrFail($id); + Session::keep('prev-url'); return view('pages.editpost', compact('data')); } @@ -126,8 +130,8 @@ class NewsController extends Controller $post->text = $request->text; $post->saveOrFail(); - return Redirect::route('news')->with('status', "Post edited."); - } else return Redirect::route('news'); + return Redirect::to(Session::get('prev-url', route('news')))->with('status', "Post edited."); + } else return Redirect::to(Session::get('prev-url', route('news'))); } /** -- cgit v1.2.3