From 3ff7e365c4aedbc47d642a07181cae45269a329d Mon Sep 17 00:00:00 2001 From: Mateja Date: Sat, 7 Nov 2020 01:41:03 +0100 Subject: Better news. I should implement url()->previous(); Gallery doesn't delete from storage... --- app/Http/Controllers/GalleryController.php | 6 +++++- app/Http/Controllers/NewsController.php | 11 +++++------ resources/views/pages/news-admin.blade.php | 22 --------------------- resources/views/pages/news.blade.php | 31 +++++++++++++++++++++--------- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/GalleryController.php b/app/Http/Controllers/GalleryController.php index 064be02..d2a04c5 100644 --- a/app/Http/Controllers/GalleryController.php +++ b/app/Http/Controllers/GalleryController.php @@ -8,6 +8,7 @@ use dd; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Validator; +use Illuminate\Support\Facades\Storage; use App\Models\Image; @@ -102,7 +103,10 @@ class GalleryController extends Controller */ public function destroy($id) { - Image::findOrFail($id)->delete(); + $img = Image::findOrFail($id); + $path = $img->path . $img->name; + Storage::delete($path); + $img->delete(); return Redirect::back()->with('status', 'Image deleted.'); } } diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php index de7a823..8be535e 100644 --- a/app/Http/Controllers/NewsController.php +++ b/app/Http/Controllers/NewsController.php @@ -34,9 +34,8 @@ class NewsController extends Controller */ public function create() { - // - $data = Post::orderBy('created_at', 'desc')->get(); - return view('pages.news-admin', compact('data')); + //$data = Post::orderBy('created_at', 'desc')->get(); + return view('pages.news-admin');//, compact('data')); } /** @@ -127,8 +126,8 @@ class NewsController extends Controller $post->text = $request->text; $post->saveOrFail(); - return Redirect::route('newsAdd')->with('statusE', "Post edited."); - } else return Redirect::route('newsAdd'); + return Redirect::route('news')->with('status', "Post edited."); + } else return Redirect::route('news'); } /** @@ -142,6 +141,6 @@ class NewsController extends Controller $post = Post::findOrFail($id); $title = $post->title; $post->delete(); - return Redirect::back()->with('statusE', "Post \"$title\" deleted."); + return Redirect::back()->with('status', "Post \"$title\" deleted."); } } diff --git a/resources/views/pages/news-admin.blade.php b/resources/views/pages/news-admin.blade.php index 55c94e6..67e64ad 100644 --- a/resources/views/pages/news-admin.blade.php +++ b/resources/views/pages/news-admin.blade.php @@ -5,28 +5,6 @@ @section('navbar', View::make('inc.navbar')) @section('content') -

News Administration:

- @if (session('statusE')) -
- {{ session('statusE') }} -
- @endif - @if (count($data) > 0) -
- - @foreach ($data as $row) - - - - - - @endforeach -
{{ $row->title }}EditDelete
-
- @else - There are currently no callsigns. - @endif -

Add Post:

@if (session('status'))
diff --git a/resources/views/pages/news.blade.php b/resources/views/pages/news.blade.php index d700ce7..33ff039 100644 --- a/resources/views/pages/news.blade.php +++ b/resources/views/pages/news.blade.php @@ -3,14 +3,27 @@ @section('title', 'News') @section('content') - @foreach($news as $post) -
-
-

{{ $post->title }}

-
Published at {{ $post->created_at->format('Y-m-d') }}@isset ($post->author) by {{$post->author }}@endisset
-
{!! $post->text !!}
+ @if (session('statusE')) +
+ {{ session('status') }} +
+ @endif + @if (count($news) > 0) + @foreach($news as $post) +
+
+

{{ $post->title }}

+
Published at {{ $post->created_at->format('Y-m-d') }}@isset ($post->author) by {{$post->author }}@endisset
+
{!! $post->text !!}
+
+
-
- @endforeach - {{ $news->links() }} + @endforeach + {{ $news->links() }} + @else + There are no news. + @endif @endsection() -- cgit v1.2.3