Commit 3359f6d3 by Hussain Mohamed

Products Store

parent 052812e4
......@@ -3,9 +3,86 @@
namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;
use App\Models\CategoryModel;
use App\Models\ProductAttributeModel;
use App\Models\ProductBrandModel;
use App\Models\ProductIndustryModel;
use App\Models\ProductModel;
use App\Models\ProductTypeModel;
use App\Models\SizeModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
class ProductController extends Controller
{
//
public function products()
{
$records = ProductModel::orderBy('id', 'ASC')->get();
return view('backend.products.list', compact('records'));
}
public function addProduct($id = '')
{
$categoryData = CategoryModel::Where('status', 1)->get();
$sizeData = SizeModel::Where('status', 1)->get();
$industryData = ProductIndustryModel::Where('status', 1)->get();
$typeData = ProductTypeModel::Where('status', 1)->get();
$brandData = ProductBrandModel::Where('status', 1)->get();
if ($id > 0) {
$record = ProductModel::Where('id', $id)->first();
return view('backend.products.edit', compact('record', 'categoryData', 'sizeData', 'brandData', 'typeData', 'industryData'));
} else {
return view('backend.products.add', compact('categoryData', 'sizeData', 'typeData', 'brandData', 'industryData'));
}
}
public function storeUpdateproducts(Request $request)
{
$input = $request->all();
$id = $input['id'];
$product_name = isset($input['product_name']) ? $input['product_name'] : '';
$category_id = isset($input['category_id']) ? $input['category_id'] : '';
$industry_id = isset($input['industry_id']) ? $input['industry_id'] : '';
$brand_id = isset($input['brand_id']) ? $input['brand_id'] : '';
$type_id = isset($input['type_id']) ? $input['type_id'] : '';
$product_description = isset($input['product_description']) ? $input['product_description'] : '';
$product_type = isset($input['size_type']) ? $input['size_type'] : '';
$product_size = isset($input['size']) ? $input['size'] : '';
if ($id == "") {
/* Insert */
$insertArr = array(
'product_name' => $product_name,
'category_id' => implode(",",$category_id),
'industry_id' => implode(",",$industry_id),
'brand_id' => implode(",",$brand_id),
'type_id' => $type_id,
'product_description' => $product_description,
);
$insert = ProductModel::create($insertArr);
if($insert['id'] > 0)
{
if ($request->hasFile('product_image')) {
$images = $request->file('product_image');
foreach($images as $key=>$image)
{
$imageName = 'product_image' . time() . '_' . str_replace(' ', '_', $image->getClientOriginalName());
$image->move(public_path('/uploads/product_image/'), $imageName);
$imageUrl = URL::to('/') . '/uploads/product_image/' . $imageName;
$insertAr = array(
'product_id' => $insert['id'],
'product_image' => $imageUrl,
'product_type' => $product_type[$key],
'product_size' => $product_size[$key]
);
ProductAttributeModel::create($insertAr);
}
}
return redirect()->route('products')->with('success', 'Pages Saved Successfully');
}
}
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ProductAttributeModel extends Model
{
use HasFactory;
protected $table = 'product_attributes';
protected $guarded = ['id'];
}
......@@ -8,4 +8,7 @@
class ProductModel extends Model
{
use HasFactory;
protected $table = 'products';
protected $guarded = ['id'];
}
......@@ -306,6 +306,12 @@
</a>
</li>
<li class="pe-slide-item">
<a href="<?= route('products') ?>" class="pe-nav-link @if(request()->routeIs(['products', 'addProduct'])) active @endif">
Products
</a>
</li>
</ul>
</li>
......
@extends('backend.app_template')
@section('title','Product Add')
@section('content')
<main class="app-wrapper">
<div class="container-fluid">
<div class="d-flex align-items-center mt-2 mb-2">
<div class="flex-shrink-0">
<nav aria-label="breadcrumb">
<ol class="breadcrumb justify-content-end mb-0">
<li class="breadcrumb-item"><a href="javascript:void(0)">Product Add</a></li>
<li class="breadcrumb-item active" aria-current="page"></li>
</ol>
</nav>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-xxl-12">
<form method="POST" id="countryForm" action="<?= route('storeUpdateproducts') ?>" enctype="multipart/form-data">
@csrf
<div>
<div class="card">
<span></span>
<!-- Logistics Details Section -->
<div class="card-header">
<h5 class="mb-0">Add Product</h5>
<div class="float-end">
<a href="<?= route('products') ?>" class="btn btn-primary">Back</a>
</div>
</div>
<input type="hidden" name="id" value="" />
<div class="card-body">
<div class="row g-4">
<div class="col-xl-4">
<label for="product_name" class="form-label">Product Name<span class="text-danger"> *</span></label>
<input type="text" value="" class="form-control" id="product_name" name="product_name" placeholder="Enter Product Name">
@error('product_name') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="category_id" class="form-label">Category<span class="text-danger"> *</span></label>
<select class="form-control select2" multiple id="category_id" name="category_id[]">
<option value="">--select--</option>
<?php
if (isset($categoryData)) {
foreach ($categoryData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->category_name) ?></option>
<?php }
} ?>
</select>
@error('category_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="industry_id" class="form-label">Industry<span class="text-danger"> *</span></label>
<select class="form-control select2" multiple id="industry_id" name="industry_id[]">
<option value="">--select--</option>
<?php
if (isset($industryData)) {
foreach ($industryData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->industry) ?></option>
<?php }
} ?>
</select>
@error('industry_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="brand_id" class="form-label">Brand<span class="text-danger"> *</span></label>
<select class="form-control select2" multiple id="brand_id" name="brand_id[]">
<option value="">--select--</option>
<?php
if (isset($brandData)) {
foreach ($brandData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->brand) ?></option>
<?php }
} ?>
</select>
@error('brand_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="type_id" class="form-label">Type<span class="text-danger"> *</span></label>
<select class="form-control select2" id="type_id" name="type_id">
<option value="">--select--</option>
<?php
if (isset($typeData)) {
foreach ($typeData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->type) ?></option>
<?php }
} ?>
</select>
@error('type_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-12">
<label for="type_id" class="form-label">Product Description</label>
<textarea class="form-control" id="product_description" name="product_description"></textarea>
</div>
<table style="width:100%" class="table">
<tr>
<th>Image</th>
<th>Product Type</th>
<th>Product Size</th>
<th>Action</th>
</tr>
<tbody id="invoiceBody">
<tr class="all_tr_td_values">
<td style="width:20%">
<input data-row="0" data-name="product_image" id="product_image0" type="file" name="product_image[]" id="product_image" class="form-control">
</td>
<td style="width:20%">
<select class="form-control select2" data-row="0" data-name="size_type" id="size_type0" name="size_type[]">
<option value="">--select--</option>
<option value="1">Size</option>
<option value="2">Range</option>
<option value="3">Capacity</option>
</select>
</td>
<td style="width:20%">
<select class="form-control select2" data-row="0" data-name="size" id="size0" name="size[]">
<option value="">--select--</option>
<?php
if (isset($sizeData)) {
foreach ($sizeData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->size) ?></option>
<?php } } ?>
</select>
</td>
<td style="width:10%">
<button type="button" class="btn btn-sm btn-success" onclick="addRow('invoiceBody');"><i class="bi bi-plus"></i></button>
<button type="button" data-row="0" id="delete" onclick="deleteItem(this)" class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-end gap-3 my-5">
<a href="" class="btn btn-light-light text-muted">Cancel</a>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
<!-- Submit Section -->
</div>
</main>
<script type="text/javascript" src="//cdn.ckeditor.com/4.5.1/standard/ckeditor.js"></script>
<script>
CKEDITOR.config.versionCheck = false;
CKEDITOR.replace('product_description');
function addRow(content_id, label_checkbox = '') {
var row = $("#" + content_id + " tr:last");
row.find("select").each(function(index) {
$(this).select2('destroy');
});
row.clone().find("input, textarea, select, button, checkbox, radio, label").each(function(j, obj) {
i = $(this).data('row') + 1;
id = $(this).data('name') + i;
$(this).val('').attr({
'id': id,
'data-row': i
});
}).end().appendTo("#" + content_id);
row.find("select").each(function(index) {
$("select").select2();
});
}
function deleteItem(e) {
var id = e.dataset.row;
if (id != 0) {
if (confirm("are you sure you want delete?") === true) {
$('#product_image' + id).parent().parent().remove();
}
}
}
$(function() {
$("#countryForm").validate({
rules: {
eye_color: {
required: true
},
},
messages: {
eye_color: {
required: "Please enter eye color"
},
},
errorElement: "span",
errorPlacement: function(error, element) {
error.addClass("text-danger");
error.insertAfter(element);
}
});
});
</script>
@endsection
\ No newline at end of file
@extends('backend.app_template')
@section('title','Product Edit')
@section('content')
<main class="app-wrapper">
<div class="container-fluid">
<div class="d-flex align-items-center mt-2 mb-2">
<div class="flex-shrink-0">
<nav aria-label="breadcrumb">
<ol class="breadcrumb justify-content-end mb-0">
<li class="breadcrumb-item"><a href="javascript:void(0)">Product Edit</a></li>
<li class="breadcrumb-item active" aria-current="page"></li>
</ol>
</nav>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-xxl-12">
<form method="POST" id="countryForm" action="<?= route('storeUpdateproducts') ?>" enctype="multipart/form-data">
@csrf
<div>
<div class="card">
<span></span>
<!-- Logistics Details Section -->
<div class="card-header">
<h5 class="mb-0">Edit Product</h5>
<div class="float-end">
<a href="<?= route('products') ?>" class="btn btn-primary">Back</a>
</div>
</div>
<input type="hidden" name="id" value="" />
<div class="card-body">
<div class="row g-4">
<div class="col-xl-4">
<label for="product_name" class="form-label">Product Name<span class="text-danger"> *</span></label>
<input type="text" value="" class="form-control" id="product_name" name="product_name" placeholder="Enter Product Name">
@error('product_name') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="category_id" class="form-label">Category<span class="text-danger"> *</span></label>
<select class="form-control select2" multiple id="category_id" name="category_id[]">
<option value="">--select--</option>
<?php
if (isset($categoryData)) {
foreach ($categoryData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->category_name) ?></option>
<?php }
} ?>
</select>
@error('category_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="industry_id" class="form-label">Industry<span class="text-danger"> *</span></label>
<select class="form-control select2" multiple id="industry_id" name="industry_id[]">
<option value="">--select--</option>
<?php
if (isset($industryData)) {
foreach ($industryData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->industry) ?></option>
<?php }
} ?>
</select>
@error('industry_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="brand_id" class="form-label">Brand<span class="text-danger"> *</span></label>
<select class="form-control select2" multiple id="brand_id" name="brand_id[]">
<option value="">--select--</option>
<?php
if (isset($brandData)) {
foreach ($brandData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->brand) ?></option>
<?php }
} ?>
</select>
@error('brand_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-4">
<label for="type_id" class="form-label">Type<span class="text-danger"> *</span></label>
<select class="form-control select2" id="type_id" name="type_id">
<option value="">--select--</option>
<?php
if (isset($typeData)) {
foreach ($typeData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->type) ?></option>
<?php }
} ?>
</select>
@error('type_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="col-xl-12">
<label for="type_id" class="form-label">Product Description</label>
<textarea class="form-control" id="product_description" name="product_description"></textarea>
</div>
<table style="width:100%" class="table">
<tr>
<th>Image</th>
<th>Product Type</th>
<th>Product Size</th>
<th>Action</th>
</tr>
<tbody id="invoiceBody">
<tr class="all_tr_td_values">
<td style="width:20%">
<input data-row="0" data-name="product_image" id="product_image0" type="file" name="product_image[]" id="product_image" class="form-control">
</td>
<td style="width:20%">
<select class="form-control select2" data-row="0" data-name="size_type" id="size_type0" name="size_type[]">
<option value="">--select--</option>
<option value="1">Size</option>
<option value="2">Range</option>
<option value="3">Capacity</option>
</select>
</td>
<td style="width:20%">
<select class="form-control select2" data-row="0" data-name="size" id="size0" name="size[]">
<option value="">--select--</option>
<?php
if (isset($sizeData)) {
foreach ($sizeData as $val) { ?>
<option value="<?php echo $val->id ?>"><?php echo ucwords($val->size) ?></option>
<?php } } ?>
</select>
</td>
<td style="width:10%">
<button type="button" class="btn btn-sm btn-success" onclick="addRow('invoiceBody');"><i class="bi bi-plus"></i></button>
<button type="button" data-row="0" id="delete" onclick="deleteItem(this)" class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-end gap-3 my-5">
<a href="" class="btn btn-light-light text-muted">Cancel</a>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
<!-- Submit Section -->
</div>
</main>
<script type="text/javascript" src="//cdn.ckeditor.com/4.5.1/standard/ckeditor.js"></script>
<script>
CKEDITOR.config.versionCheck = false;
CKEDITOR.replace('product_description');
function addRow(content_id, label_checkbox = '') {
var row = $("#" + content_id + " tr:last");
row.find("select").each(function(index) {
$(this).select2('destroy');
});
row.clone().find("input, textarea, select, button, checkbox, radio, label").each(function(j, obj) {
i = $(this).data('row') + 1;
id = $(this).data('name') + i;
$(this).val('').attr({
'id': id,
'data-row': i
});
}).end().appendTo("#" + content_id);
row.find("select").each(function(index) {
$("select").select2();
});
}
function deleteItem(e) {
var id = e.dataset.row;
if (id != 0) {
if (confirm("are you sure you want delete?") === true) {
$('#product_image' + id).parent().parent().remove();
}
}
}
$(function() {
$("#countryForm").validate({
rules: {
eye_color: {
required: true
},
},
messages: {
eye_color: {
required: "Please enter eye color"
},
},
errorElement: "span",
errorPlacement: function(error, element) {
error.addClass("text-danger");
error.insertAfter(element);
}
});
});
</script>
@endsection
\ No newline at end of file
@extends('backend.app_template')
@section('title','Product List')
@section('content')
<main class="app-wrapper">
<div class="container-fluid">
<div class="d-flex align-items-center mt-2 mb-2">
<div class="flex-shrink-0">
<nav aria-label="breadcrumb">
<ol class="breadcrumb justify-content-end mb-0">
<li class="breadcrumb-item"><a href="javascript:void(0)">Product</a></li>
<li class="breadcrumb-item active" aria-current="page">List</li>
</ol>
</nav>
</div>
</div>
<div class="row">
<div class="d-flex justify-content-end mb-4">
<a href="<?php echo route('addProduct') ?>" class="btn btn-primary">Add Product</a>
</div>
<table id="datatables" class="table table-nowrap table-hover table-bordered w-100 mt-5">
<thead>
<tr>
<th>S.No</th>
<th>Category Name</th>
<th>Product Name</th>
<th>Product Type</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (isset($records)) {
$i = 1;
foreach ($records as $key => $row) {
?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo $row->category_name ?></td>
<td><?php echo $row->product_name ?></td>
<td><?php echo $row->type ?></td>
<td><a data-placement="top" title="Status" data-original-title="Status" href="javascript:void(0)" onclick="changeStatus('<?php echo $row->id ?>','<?php echo ($row->status == 1) ? 0 : 1 ?>','ProductModel')" class="badge bg-pill bg-<?php echo ($row->status == 1) ? 'success' : 'danger' ?>"><?php echo ($row->status == 1) ? 'Active' : 'In-Active' ?></a></td>
<td>
<a data-toggle="tooltip" data-placement="top" title="Edit" href="<?php echo route('addProduct', [$row->id]) ?>" class="btn btn-sm btn-warning"><i class="bi bi-pencil-fill"></i></a>
<a data-toggle="tooltip" data-placement="top" title="Delete" data-original-title="Delete" href="javascript:void(0)" onclick="commonDelete('<?php echo $row->id ?>','ProductModel')" class="btn btn-sm btn-danger"><i class="bi bi-trash-fill"></i></a>
</td>
</tr>
<?php $i++;
}
} ?>
</tbody>
</table>
</div>
<!-- Submit Section -->
</div>
</main>
@endsection
\ No newline at end of file
......@@ -14,6 +14,7 @@
use App\Http\Controllers\Backend\MetaController;
use App\Http\Controllers\Backend\OrientationController;
use App\Http\Controllers\Backend\PageController;
use App\Http\Controllers\Backend\ProductController;
use App\Http\Controllers\Backend\ReportsController;
use App\Http\Controllers\Backend\UserController;
use App\Http\Controllers\Backend\SettingsController;
......@@ -59,6 +60,10 @@
Route::get('addCategory/{id?}', [CategoryController::class, 'addCategory'])->name('addCategory');
Route::post('storeUpdateCategory', [CategoryController::class, 'storeUpdateCategory'])->name('storeUpdateCategory');
Route::get('products', [ProductController::class, 'products'])->name('products');
Route::get('addProduct/{id?}', [ProductController::class, 'addProduct'])->name('addProduct');
Route::post('storeUpdateproducts', [ProductController::class, 'storeUpdateproducts'])->name('storeUpdateproducts');
Route::get('size', [SizeController::class, 'size'])->name('size');
Route::get('addSize/{id?}', [SizeController::class, 'addSize'])->name('addSize');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment