Sfoglia il codice sorgente

archivia e ripristina in admin

FabioFratini 1 anno fa
parent
commit
871510f83d

+ 1 - 7
app/Http/Controllers/CalendarController.php

@@ -4,13 +4,10 @@ namespace App\Http\Controllers;
 
 use App\Calendar;
 use App\CalendarGame;
-use App\Category;
 use App\Season;
-use App\Group;
 use App\Team;
 use Illuminate\Http\Request;
-use File;
-
+use Illuminate\Support\Facades\File;
 class CalendarController extends Controller
 {
 
@@ -20,10 +17,7 @@ class CalendarController extends Controller
 
     public function index()
     {
-        if (isset($_GET["all"]))
             $calendars = Calendar::orderBy('position')->orderBy('name')->get(); //->paginate(50);
-        else
-            $calendars = Calendar::where('archived', null)->orderBy('position')->orderBy('name')->get(); //->paginate(50);
 
         return view('calendars.index',compact('calendars'))
             ->with('i', (request()->input('page', 1) - 1) * 5);

+ 6 - 2
resources/views/calendars/index.blade.php

@@ -38,8 +38,12 @@
                           <a href="{{ route('calendars.edit', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-primary">Importa calendario</a>
                       </td>
                       <td>
-                          <a href="{{ route('calendars.archive', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-warning">Archivia</a>
-                      </td>
+                        @if($calendar->archived)
+                            <a href="{{ route('calendars.restore', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-success">Ripristina</a>
+                        @else
+                            <a href="{{ route('calendars.archive', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-warning">Archivia</a>
+                        @endif
+                    </td>
                       <td>
                         {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('calendars.destroy', $calendar->id))) !!}
                             <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>

+ 7 - 0
routes/web.php

@@ -2656,6 +2656,13 @@ Route::group(['middleware' => 'auth'], function () {
             return Redirect::to('/admin/calendars');
         })->name('calendars.archive');
 
+        Route::get('/calendars/restore/{id}', function ($id) {
+            $c = Calendar::findOrFail($id);
+            $c->archived = false;
+            $c->save();
+            return Redirect::to('/admin/calendars');
+        })->name('calendars.restore');
+
         Route::get('/calendars/games/{id}', function ($id) {
 
             $calendar = CalendarGame::where('calendar_id', '=', $id)->get();;