<?php

// namespace App\Http\Controllers;

// use Illuminate\Http\Request;

// class ProductsController extends Controller
{
    //
}

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\Products;

class ProductsController extends Controller
{


    /**
     * Listing Of images gallery
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
    	$images = Products::get();
        return view('projects') -> with ('images', $images);
    }


    /**
     * Upload image function
     *
     * @return \Illuminate\Http\Response
     */
    public function upload(Request $request)
    {
    	$this->validate($request, [
    		'title' => 'required',
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);


        $input['image'] = time().'.'.$request->image->getClientOriginalExtension();
        $request->image->move(public_path('images'), $input['image']);


        $input['title'] = $request->title;
        Products::create($input);


    	return back()
    		->with('success','Image Uploaded successfully.');
    }


    /**
     * Remove Image function
     *
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
    	Products::find($id)->delete();
    	return back()
    		->with('success','Image removed successfully.');
    }
}
