<?php

namespace App\Http\Controllers\Dashboard;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreGallery;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use App\User; 
use App\Gallery;
use App\ImageUpload;
use Auth;
use File;
use Validator; 

class Galleries extends Controller
{

    /**
     * Show the middleware dashboard Super-Admin.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function __construct()
    {
        $this->middleware(['auth','role_or_permission:Super-Admin|edit articles']);
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         // GET Galleries
        $Galleries = Gallery::simplePaginate(10);
        return view('Dashboard.Galleries.index',compact('Galleries'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        // GET dashboardRoles create
        return view('Dashboard.Galleries.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        $ImageUpload = ImageUpload::max('id');
        Gallery::create([   
            'ImageUpload_id' => $ImageUpload
        ]);

            return redirect()->route('Galleries.index')

                        ->with('success','Galleries Store successfully.');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        // Gallery Delete
        $Gallery = Gallery::findOrFail($id);
        $Gallery->delete();
        return back()->with('Delete','Galleries deleted successfully');
    }
}
