<file_sep><?php

namespace App\Http\Controllers;

use App\Models\Clothing;
use Illuminate\Http\Request;

class ClothingController extends Controller
{
    public function index()
    {
        $clothings = Clothing::latest()->get();

        return view('admin/index', [

            'clothings' => $clothings]);
    }

    public function order(Request $request)
    {

        if ($request->isMethod('get'))
            return view('create');
        elseif ($request->isMethod('post')) {
            $rules = [
                'name' => 'required',
                'material' => 'nullable|sometimes',
                'color' => 'required',
                'size' => 'required',
                'address' => 'required',
                'gender' => 'required',
                'phone' => 'required',
                'email' => 'required',
                'image' => 'nullable|sometimes|image|mimes:jpeg,bmp,png,jpg,svg|max:500',
            ];


            $clothing = new Clothing();

            $clothing->material = request('material');
            $clothing->color = request('color');
            $clothing->address = request('address');
            $clothing->name = request('name');
            $clothing->gender = request('gender');
            $clothing->size = request('size');
            $clothing->email = request('email');
            $clothing->phone = request('phone');
            $clothing->image = '';

            if ($request->hasfile('image')) {
                $file = $request->file('image');
                $extension = $file->getClientOriginalExtension();
                $filename = $request->file('image')->getClientOriginalName();
                $file->move('uploads/avatars', $filename);
                $clothing->image = $filename;
            }


            $clothing->save();

            return redirect('/')->with('success', 'Thanks for your order, you will be notified soon');
        }
    }

    public function showa($id)
    {

        $clothing = Clothing::findOrFail($id);

        return view('admin/show', ['clothing' => $clothing]);
    }

    public function destroy($id)
    {

        $clothing = Clothing::findOrFail($id);
        $clothing->delete();

        return redirect('/clothings');
    }

    public function edit($id)
    {
        $clothing = Clothing::findOrFail($id);

        return view('clothings.edit', ['clothing' => $clothing]);
    }


    public function update(Request $request, $id)
    {
        $this->validate($request, [
            'name' => 'required',
            'email' => 'required',
            'phone' => 'required',
            'gender' => 'required',
            'date' => 'required',
            'material' => 'required',
            'color' => 'required',
            'style' => 'required',
            'size' => 'required',
            'additionaldetails' => 'required'

        ]);
        $clothing = Clothing::find($id);

        $clothing->material = request('material');
        $clothing->color = request('color');
        $clothing->style = request('style');
        $clothing->name = request('name');
        $clothing->gender = request('gender');
        $clothing->date = request('date');
        $clothing->size = request('size');
        $clothing->email = request('email');
        $clothing->phone = request('phone');
        $clothing->additionaldetails = request('additionaldetails');

        $clothing->save();

        return redirect('/')->with('mssg', 'Update Successful');
    }

}
<file_sep>-- phpMyAdmin SQL Dump
-- version 4.9.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Sep 30, 2020 at 10:52 AM
-- Server version: 10.4.10-MariaDB
-- PHP Version: 7.3.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `clothing`
--

-- --------------------------------------------------------

--
-- Table structure for table `clothings`
--

DROP TABLE IF EXISTS `clothings`;
CREATE TABLE IF NOT EXISTS `clothings` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `material` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `color` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `gender` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `size` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `clothings`
--

INSERT INTO `clothings` (`id`, `material`, `color`, `name`, `gender`, `size`, `email`, `phone`, `image`, `address`, `created_at`, `updated_at`) VALUES
(1, 'Irish', 'Blue', '<NAME>', 'Male', '19, 20, 42, 36', '<EMAIL>', '08039093831', 'IMG_20190105_023001_361.JPG.jpg', 'Ran Road', '2020-09-29 15:36:00', '2020-09-29 15:36:00'),
(2, 'Irish', 'Brown', '<NAME>', 'Male', '19, 20, 42, 36', '<EMAIL>', '08036474862', 'IMG_20190114_041446_679.JPG.jpg', '<NAME>', '2020-09-29 20:22:45', '2020-09-29 20:22:45');

-- --------------------------------------------------------

--
-- Table structure for table `failed_jobs`
--

DROP TABLE IF EXISTS `failed_jobs`;
CREATE TABLE IF NOT EXISTS `failed_jobs` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `connection` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `fromgallery`
--

DROP TABLE IF EXISTS `fromgallery`;
CREATE TABLE IF NOT EXISTS `fromgallery` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `galleries_id` int(11) NOT NULL,
  `material` varchar(255) DEFAULT NULL,
  `color` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `size` varchar(255) NOT NULL,
  `gender` varchar(60) NOT NULL,
  `address` varchar(255) NOT NULL,
  `email` varchar(150) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `galleries`
--

DROP TABLE IF EXISTS `galleries`;
CREATE TABLE IF NOT EXISTS `galleries` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `material` varchar(200) NOT NULL,
  `style` varchar(200) DEFAULT NULL,
  `color` varchar(200) NOT NULL,
  `image2` varchar(200) DEFAULT NULL,
  `price` varchar(150) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `galleries`
--

INSERT INTO `galleries` (`id`, `material`, `style`, `color`, `image2`, `price`, `created_at`, `updated_at`) VALUES
(1, 'Cashmire', 'South South', 'Blue', 'IMG_20190105_023001_361.JPG.jpg', '2500', '2020-09-27 18:14:40', '2020-09-27 18:14:40'),
(2, 'Cashmire', 'South West', 'Green', 'BILLIE-EILISH.jpg', '3000', '2020-09-28 03:59:28', '2020-09-28 03:59:28'),
(3, 'Irish', 'Half Jumper', 'Brown', 'IMG_20190114_041403_325.JPG.jpg', '5000', '2020-09-28 04:02:12', '2020-09-28 04:02:12'),
(4, 'Plain', 'Jumper', 'White', 'IMG_20190114_041318_202.JPG.jpg', '6000', '2020-09-28 04:38:02', '2020-09-28 04:38:02');

-- --------------------------------------------------------

--
-- Table structure for table `migrations`
--

DROP TABLE IF EXISTS `migrations`;
CREATE TABLE IF NOT EXISTS `migrations` (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `migrations`
--

INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
(1, '2014_10_12_000000_create_users_table', 1),
(2, '2019_08_19_000000_create_failed_jobs_table', 1),
(3, '2020_03_23_100522_create_clothings_table', 1);

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `usertype` int(1) NOT NULL DEFAULT 0,
  `fullname` varchar(200) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `email` varchar(160) NOT NULL,
  `password` varchar(100) NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `active` int(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `phone` (`phone`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `usertype`, `fullname`, `phone`, `email`, `password`, `created_at`, `updated_at`, `active`) VALUES
(1, 1, '<NAME>', '08039093831', '<EMAIL>', '<PASSWORD>', '2020-09-27 19:36:38', '2020-09-27 19:36:38', 1);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Session;

class BaseController extends Controller
{
    public function __construct()
    {

    }

    public function dologout(Request $request)
    {
        Session()->flush();
        return redirect('/');
    }

    protected function isLoggedIn()
    {
        $user = Session::get('logged_user');
        if (!isset($user->id)) {
            // Session::flash('warning','Please log in to proceed!');
            return false;
        } else {
            return true;
        }
    }
}
<file_sep><?php

use App\Http\Controllers\ClothingController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\GalleryController;
use App\Http\Controllers\SigninController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/dashboard', [DashboardController::class, 'index']);

Route::match(['get', 'post'], '/signin', [SigninController::class, 'index']);

Route::match(['get', 'post'], 'gallery', [GalleryController::class, 'gallery']);

Route::match(['get', 'post'], 'admin/creategallery', [GalleryController::class, 'creategallery']);


Route::match(['get', 'post'], '/clothings', [ClothingController::class, 'index']);

Route::match(['get', 'post'], '/order', [ClothingController::class, 'order']);

Route::get('/{id}', [ClothingController::class, 'show']);

Route::get('a/{id}', [ClothingController::class, 'showa']);

Route::match(['get', 'post'], '/register', [SigninController::class, 'register']);


Route::get('/{id}', [GalleryController::class, 'show']);

Route::match(['get', 'post'], '/orderg', [GalleryController::class, 'orderg']);


Route::group(array('prefix' => 'admin'), function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
    Route::get('/logout', [DashboardController::class, 'logout']);
    Route::get('/{id}', [ClothingController::class, 'show']);
    Route::match(['get', 'post'], 'admin/creategallery', [GalleryController::class, 'creategallery']);
    Route::match(['get', 'post'], '/changepassword', [ProfileController::class, 'changepassword']);
    Route::match(['get', 'post'], '/updateprofile', [ProfileController::class, 'updateprofile']);
});


<file_sep><?php

namespace App\Http\Controllers;

use App\Models\Fgallery;
use App\Models\Gallery;
use Illuminate\Http\Request;

class GalleryController extends BaseController
{

    public function __construct()
    {

    }

    public function gallery(Request $request)
    {
        $gallery = Gallery::all();

        return view('gallery', ['gallery' => $gallery]);
    }

    public function creategallery(Request $request)
    {
        if ($request->isMethod('get'))
            return view('admin/creategallery');
        elseif ($request->isMethod('post')) {
            $rules = [
                'material' => 'required',
                'style' => 'nullable|sometimes',
                'color' => 'required',
                'price' => 'required',
                'image2' => 'nullable|sometimes|image|mimes:jpeg,bmp,png,jpg,svg|max:500',
            ];

            $gallery = new Gallery();


            $gallery->material = request('material');
            $gallery->style = request('style');
            $gallery->color = request('color');
            $gallery->price = request('price');
            $gallery->image2 = '';

            if ($request->hasfile('image2')) {
                $file = $request->file('image2');
                $extension = $file->getClientOriginalExtension();
                $filename = $request->file('image2')->getClientOriginalName();
                $file->move('uploads/avatars', $filename);
                $gallery->image2 = $filename;
            }

            $gallery->save();
            return redirect()->back()->with('success', 'Style Successfuly uploaded');

        }
    }

    public function orderg(Request $request)
    {

        // storing a review

        $clothing = new Fgallery();

        $clothing->material = request('material');
        $clothing->galleries_id = request('pid');
        $clothing->color = request('color');
        $clothing->address = request('address');
        $clothing->name = request('name');
        $clothing->gender = request('gender');
        $clothing->size = request('size');
        $clothing->email = request('email');
        $clothing->phone = request('phone');

        $clothing->save();

        return redirect('/')->with('success', 'Thanks for your order, you will be notified soon');
    }


    public function show($id)
    {
        $gallery = Gallery::findOrFail($id);

        return view('show', ['gallery' => $gallery, 'c' => $id]);
    }


}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Gallery extends Model
{
    protected $table = 'galleries';

    public function orderg()
    {
        return $this->belongsToMany('App\Model\Fgallery');
    }

}
<file_sep><?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Clothing extends Model
{
    protected $table = 'clothings';

}
<file_sep><?php

namespace App\Http\Controllers;

use App\Models\Users;
use Illuminate\Http\Request;
use Session;

class SigninController extends BaseController
{
    public function index(Request $request)
    {
        if ($request->isMethod('get'))
            return view('signin');
        elseif ($request->isMethod('post')) {
            $rules = [
                'email' => 'required',
                'password' => '<PASSWORD>'
            ];
            $validator = Validator()->make($request->all(), $rules);
            if ($validator->fails()) {
                return redirect()->back()->withInput()->withErrors($validator);
            } else {
                $e = $request->email;
                $p = md5($request->password);
                $obj = Users::whereRaw("(email = '$e' OR phone = '$e') AND password = '$p'")->get();
                if ($obj && count($obj) > 0) {
                    Session::put('logged_user', $obj[0]);
                    Session::save();
                    return redirect('admin/dashboard');
                } else {
                    return redirect()->back()->with('error', 'Invalid login details. Please try again.');
                }
            }
        }
    }

    public function register(Request $request)
    {
        // return view('faq');
        if ($request->isMethod('get'))
            return view('register');
        elseif ($request->isMethod('post')) {
            $rules = [
                'fullname' => 'required',
                'phone' => 'required|unique:users,phone',
                'email' => 'required|email|unique:users,email',
                'password' => '<PASSWORD>',
                'cpassword' => '<PASSWORD>'
            ];
            $passchecked = ($request->password !== $request->cpassword);
            $validator = Validator()->make($request->all(), $rules);
            if ($validator->fails() || $passchecked) {
                if ($passchecked)
                    $validator->errors()->add('password', 'The password and confirm password must be the same');
                return redirect()->back()->withInput()->withErrors($validator);
            } else {
                $obj = new Users;
                $obj->usertype = 1;
                $obj->active = 1;
                $obj->fullname = $request->fullname;
                $obj->phone = $request->phone;
                $obj->email = $request->email;
                $obj->password = md5($request->password);
                // print_r($obj);exit;
                if ($obj->save()) {
                    return redirect()->back()->with('success', 'Your account has been created successfully. Please signin to continue to your dashboard.');
                } else {
                    return redirect()->back()->with('error', 'Invalid login details. Please try again.');
                }
            }
        }
    }
}
<file_sep><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DashboardController extends BaseController
{
    public function __construct()
    {

    }

    public function index(Request $request)
    {
        if ($this->isLoggedIn()) {
            return view("admin/dashboard");
        } else {
            return redirect('/')->with('warning', 'Please log in to proceed!');
        }
    }

    public function logout(Request $request)
    {
        return $this->dologout($request);
    }

}
