Skip to content

Commit

Permalink
update userTemp
Browse files Browse the repository at this point in the history
  • Loading branch information
Abu-Salah-Musha-Lemon committed Aug 2, 2024
1 parent e9fe911 commit b4744a7
Show file tree
Hide file tree
Showing 64 changed files with 54,507 additions and 66 deletions.
43 changes: 43 additions & 0 deletions app/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\category;
use App\Models\subcategory;
use App\Models\product;
class ClientController extends Controller
{

public function CategoryPage($id){
$category = Category::where($id)->FindOrFild()->get();
return view('userTemp.categoryPage',compact('category'));
}


// public function singleProduct(){
// return view('userTemp.categoryPage');
// }
public function addToCart(){
return view('userTemp.singlePage');
}
public function checkout(){
return view('userTemp.checkOut');
}
public function userProfile(){
return view('userTemp.userProfile');
}
public function newRelease(){
return view('userTemp.newRelease');
}
public function todaysDeal(){
return view('userTemp.todaysDeal');
}
public function customerService(){
return view('userTemp.customerService');
}




}
53 changes: 53 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\category;
use App\Models\subcategory;
use App\Models\product;
class HomeController extends Controller
{

public function index()
{
// $category = Category::where($id)->FindOrFild()->get();
return view('userTemp.home');
}


public function create()
{
//
}


public function store(Request $request)
{
//
}


public function show(string $id)
{
//
}


public function edit(string $id)
{
//
}


public function update(Request $request, string $id)
{
//
}


public function destroy(string $id)
{
//
}
}
21 changes: 17 additions & 4 deletions app/Http/Controllers/admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public function store(Request $request)
'product_img' => $img_name, // Ensure consistency here
'slug' => strtolower(str_replace(' ', '-', $request->input('product_name')))
]);
// Update the product count in the related category and subcategory
$category_id = $request->input('product_category_id');
$subcategory_id = $request->input('product_subcategory_id');

Category::where('id', $category_id)->increment('product_count',1);
SubCategory::where('id', $subcategory_id)->increment('product_count',1);

// Redirect with success message
return redirect()->route('product')->with([
'message' => 'Product created successfully!',
Expand Down Expand Up @@ -152,19 +159,25 @@ public function destroy(string $id)
{
// Step 1: Find the product by ID
$product = Product::findOrFail($id);
$cat_id = Product::where('id',$id)->value('product_category_id');
$subcat_id = Product::where('id',$id)->value('product_subcategory_id');

Category::where('id',$cat_id)->decrement('product_count',1);
SubCategory::where('id',$cat_id)->decrement('product_count',1);
// return $id;exit;
// Step 2: Delete the product image if it exists
if ($product->product_img) {
// Construct the full path to the image
$imagePath = 'public/products/' . $product->product_img;

// Check if the file exists before deleting
if (Storage::exists($imagePath)) {
Storage::delete($imagePath);
// return $imagePath;exit;
// Check if the file exists before deleting
if (file_exists($imagePath)) {
unlink($imagePath);
} else {
// Optionally log an error or message if the file doesn't exist
\Log::warning("Image not found for product ID {$id}: {$imagePath}");
}

}

// Step 3: Delete the product record
Expand Down
38 changes: 38 additions & 0 deletions database/factories/ProductFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\Product;
// use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product>
*/
class ProductFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
protected $model = Product::class;
public function definition(): array
{
return [
'product_name' => $this->faker->word(),
'product_short_des' => $this->faker->sentence(),
'product_des' => $this->faker->paragraph(),
'product_price' => $this->faker->randomFloat(2, 10, 1000),
'product_category_id' => $this->faker->numberBetween(1, 10),
// 'product_category_name' => $this->faker->word(),
'product_subcategory_id' => $this->faker->numberBetween(1, 20),
// 'product_subcategory_name' => $this->faker->word(),
'product_quantity' => $this->faker->numberBetween(1, 100),
'product_img' => $this->faker->imageUrl(),
'slug' => function (array $attributes) {
return Str::slug($attributes['product_name']);
},
];
}
}
3 changes: 0 additions & 3 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
$this->call(LaratrustSeeder::class);
Expand Down
18 changes: 18 additions & 0 deletions database/seeders/ProductSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Product;
class ProductSeeder extends Seeder
{
/**
* Run the database seeds.
*/

public function run(): void
{
Product::factory(50)->create();
}
}
Binary file added public/userTemp/css/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions public/userTemp/css/animate.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit b4744a7

Please sign in to comment.