Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
14 changes: 14 additions & 0 deletions app/Cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Cart extends Model
{
protected $fillable = [
'quantity',
'total_price',
'product_id'
];
}
20 changes: 16 additions & 4 deletions app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

class Category extends Model
{
public function product() {
return $this->hasOne('App\Product');
}

protected $fillable = [
'name',
'product_id'
];


/**
*
*
* Relation One to Many to Products Table
*/
public function productsFromCategory()
{
return $this->hasMany(Product::class);
}

public function products()
{
return $this->belongsTo(Product::class);
}
}
35 changes: 35 additions & 0 deletions app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;

class CartController extends Controller
{
public $i = 1;

public function setVal($value)
{
$this->i += $value;
}

public function getVal()
{
return $this->i;
}

public function setCart($id)
{
// session(['cart' => [$id => $i]]);

if (!empty(session()->get('cart'))) {
self::setVal(1);
session(['cart' => [$id => self::getVal()]]);
} else {
session(['cart' => [$id => 1]]);
}

return redirect()->route('index');
}
}
25 changes: 20 additions & 5 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public function index()

$categoryList = $category->all();

return view('category.index',
return view(
'category.index',
[
'categories' => $categoryList
]);
]
);
}

/**
Expand Down Expand Up @@ -77,7 +79,9 @@ public function show($id)
*/
public function edit($id)
{
//
$data = Category::find($id);

return view('category.edit', ['data' => $data]);
}

/**
Expand All @@ -89,7 +93,16 @@ public function edit($id)
*/
public function update(Request $request, $id)
{
//
$this->validate($request, [
'name' => 'required|alpha'
]);

$metaData = [
'name' => $request->name
];

Category::find($id)->update($metaData);
return redirect()->route('admin.category.index');
}

/**
Expand All @@ -100,6 +113,8 @@ public function update(Request $request, $id)
*/
public function destroy($id)
{
//
Category::find($id)->delete();

return redirect()->route('admin.category.index');
}
}
18 changes: 18 additions & 0 deletions app/Http/Controllers/ProductController-bak.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ProductController extends Controller
{
public function index()
{
return view('product.index');
}

public function create()
{
return view('product.create');
}
}
131 changes: 131 additions & 0 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;
use App\Category;
use Illuminate\Support\Facades\Auth;

class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$datas = Product::all();
return view('product.index', ['datas' => $datas]);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$categories = Category::all();
return view('product.create', ['categories' => $categories]);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'min:3|required',
'weight' => 'required',
'stock' => 'required',
'price' => 'required',
'description' => 'required|min:5',
'size' => 'required',
'color' => 'required'
]);

$idSeller = Auth::user()->id;

$datas = [
'seller_id' => $idSeller,
'category_id' => $request->category,
'name' => $request->name,
'weight' => $request->weight,
'stock' => $request->stock,
'price' => $request->price,
'discount' => $request->discount,
'description' => $request->description,
'size' => $request->size,
'color' => $request->color
];

$LastId = Product::create($datas);
$getLastId = $LastId->id;

if (!empty($request->file('image'))) {
$img = $request->file('image')->store('products');

Product::find($getLastId)->update([
'image' => $img
]);
}

return redirect()->route('admin.product.index');
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$data = Product::findOrFail($id);

return view('product.view', ['data' => $data]);
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$data = Product::find($id);

return view('product.edit', ['data' => $data]);
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
Product::findOrFail($id)->delete();

return redirect()->route('admin.product.index');
}
}
Loading