Skip to content

Commit

Permalink
Product edit and delete: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Slymee committed Jan 26, 2024
1 parent 454c313 commit 13c6718
Show file tree
Hide file tree
Showing 17 changed files with 350 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

use App\Http\Requests\CreateProductAdRequest;
use App\Models\Category;
use App\Models\ProductAd;
use App\Models\Product;
use App\Models\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Input;

class ProductAdController extends Controller
class ProductController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application
{
$user = auth()->user();
$products = ProductAd::where('user_id', $user->id)->paginate(10);
$products = Product::where('user_id', $user->id)->paginate(10);
return view('userend.my-products', compact('products'));
}

Expand Down Expand Up @@ -56,7 +56,7 @@ public function store(CreateProductAdRequest $request): \Illuminate\Http\Redirec
$imageName = 'solo' . time() . 'leveling' .'.'. $request->product_image->extension();

if($imagePath = $request->file('product_image')->storeAs('images', $imageName, 'public')){
$productAd=ProductAd::create([
$productAd=Product::create([
'user_id' => $request->input('user_id'),
'product_title' => $request->input('product_title'),
'product_description' => $request->input('product_description'),
Expand Down Expand Up @@ -100,31 +100,31 @@ public function displayChildCategory(string $parentId, Request $request): \Illum
/**
* Display the specified resource.
*/
public function show(ProductAd $productAd)
public function show(Product $productAd)
{

}

/**
* Show the form for editing the specified resource.
*/
public function edit(ProductAd $productAd)
public function edit(Product $productAd)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, ProductAd $productAd)
public function update(Request $request, Product $productAd)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(ProductAd $productAd)
public function destroy(Product $productAd)
{
//
}
Expand Down
12 changes: 6 additions & 6 deletions app/Models/ProductAd.php → app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProductAd extends Model
class Product extends Model
{
use HasFactory;

protected $table='product_ads';
protected $table='products';

protected $fillable=[
'user_id',
Expand All @@ -20,17 +20,17 @@ class ProductAd extends Model
'image_path',
'slug'
];
public function user()
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class);
}

public function categories()
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Category::class, 'product_category');
return $this->belongsToMany(Category::class, 'product_categories');
}

public function tags()
public function tags(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Tag::class, 'product_id');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class Tag extends Model
];

public function productAds(){
return $this->belongsTo(ProductAd::class, 'product_ads');
return $this->belongsTo(Product::class, 'product_ads');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
return new
class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('product_ads', function (Blueprint $table) {
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
*/
public function up(): void
{
Schema::create('product_category', function (Blueprint $table) {
Schema::create('product_categories', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('product_ad_id');
$table->unsignedBigInteger('product_id');
$table->unsignedBigInteger('category_id');
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->foreign('product_ad_id')->references('id')->on('product_ads')->onDelete('cascade');
$table->foreign('product_id')->references('id')->on('product_ads')->onDelete('cascade');
$table->timestamps();
});
}
Expand Down
35 changes: 35 additions & 0 deletions resources/css/my-products.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
section{
display: flex;
}

.side-bar{
padding: 10px;
width: 250px;
height: 100vh;
background: #2d3748;
color: white;
}

.main-container{
padding: 10px;
}

.main-container>span{
padding: 10px;
font-size: 24px;
font-weight: bold;
}

.table-container{
padding: 10px;
width: 100%;
}

td,th{
padding: 10px;
width: 700px;
text-align: center;
}
td>a>button{
width: 50%;
}
4 changes: 3 additions & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './bootstrap';

import './product-ad';
import './product-ad';

import './product-edit'
7 changes: 5 additions & 2 deletions resources/js/product-ad.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
$(document).ready(function() {
$('#subCategoryDiv').hide();
$('#subSubCategoryDiv').hide();

// Initialize Select2
$("#parentCategory").select2({
placeholder: 'Search...',
Expand Down Expand Up @@ -46,6 +49,7 @@ $(document).ready(function() {
* Getting first child category in select
*/
$('#parentCategory').on('change', function (){
$('#subCategoryDiv').show();
var mainParentId = document.querySelector('#parentCategory').value;
$("#subCategory").select2({
placeholder: 'Search...',
Expand Down Expand Up @@ -77,7 +81,6 @@ $(document).ready(function() {
},
cache: true
},
// dropdownParent: $('#scrollingSelectContainer'), // Specify the container for the dropdown
});

});
Expand All @@ -87,6 +90,7 @@ $(document).ready(function() {
* Getting first child category
*/
$('#subCategory').on('change', function (){
$('#subSubCategoryDiv').show();
var firstChildId = document.querySelector('#subCategory').value;
$("#subSubCategory").select2({
placeholder: 'Search...',
Expand Down Expand Up @@ -118,7 +122,6 @@ $(document).ready(function() {
},
cache: true
},
// dropdownParent: $('#scrollingSelectContainer'), // Specify the container for the dropdown
});

});
Expand Down
Empty file added resources/js/product-edit.js
Empty file.
6 changes: 3 additions & 3 deletions resources/views/userend/commonComponents/nav-bar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<li class="dropdown">
<button onclick="myFunction()" class="dropbtn">{{ auth()->user()->username }}</button>
<div id="myDropdown" class="dropdown-content">
<a href="{{ route('my-product-ads') }}">My Ads</a>
<a href="{{ route('my-product-ads') }}">Dashboard</a>
<a href="{{ route('user.logout') }}">Logout</a>
</div>
</li>
Expand Down Expand Up @@ -46,7 +46,7 @@ function myFunction() {
<span class="fas fa-times"></span>
</div> --}}
<form action="#">
<input type="search" class="search-data" placeholder="Search" required>
<input type="search" class="search-data" placeholder="Search Products" required>
<button type="submit" class="fas fa-search"></button>
</form>
</nav>
Expand Down Expand Up @@ -76,4 +76,4 @@ function myFunction() {
searchBtn.classList.add("hide");
cancelBtn.classList.add("show");
}
</script>
</script>
Empty file.
13 changes: 6 additions & 7 deletions resources/views/userend/create-product.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@endsection

@section('content')
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- Include Select2 CSS and JS files -->
Expand Down Expand Up @@ -70,17 +69,17 @@
@if(session('message'))
{{ session('message') }}
@endif

@if($errors->any())
@foreach ($errors->all() as $error)
<br> {{ $error }}
@endforeach
<br> {{ $error }}
@endforeach
@endif
</span>
</form>
</div>
</section>

{{-- <script>
/**
* Level 2 Category
Expand Down Expand Up @@ -191,6 +190,6 @@
});
});
</script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
@endsection
@endsection
Loading

0 comments on commit 13c6718

Please sign in to comment.