diff --git a/app/Http/Controllers/OrdersController.php b/app/Http/Controllers/OrdersController.php index 0fc77fb..4e5be1d 100644 --- a/app/Http/Controllers/OrdersController.php +++ b/app/Http/Controllers/OrdersController.php @@ -15,14 +15,16 @@ class OrdersController extends Controller */ public function index() { - // - } + // $orders = Order::all(); + // return view('orders.index', ['orders' => $orders]); + // } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ + } public function create() { return view('orders.create'); @@ -38,14 +40,12 @@ public function store(OrderCreateRequest $request) { $data = $request->only(['total_price', 'description']); $currentUserId = auth()->id(); - try { $data['user_id'] = $currentUserId; Order::create($data); } catch (Exception $e) { return back()->with('status', 'Create fail'); } - return redirect("users/$currentUserId")->with('status', 'Profile updated!'); } @@ -57,7 +57,11 @@ public function store(OrderCreateRequest $request) */ public function show($id) { - // + // $order = Order::find($id); + // if (!$order) { + // return back()->with('status', 'Order not exist'); + // } + // return view('orders.show', compact('order')); } /** @@ -80,7 +84,16 @@ public function edit($id) */ public function update(Request $request, $id) { - // + // $validated = $request->validated(); + // $data = $request->only('user_id', 'total_price', 'description', 'status'); + // $order = Order::find($id); + // try { + // $order ->update($data); + // } catch (\Exception $e) { + // dd($e->getMessage()); + // return back()->with('status', 'Update fail'); + // } + // return redirect(route('orders.show', $order->id)); } /** @@ -90,7 +103,47 @@ public function update(Request $request, $id) * @return \Illuminate\Http\Response */ public function destroy($id) + { - // + // $order = Order::find($id); + // if (!$order) { + // $result = [ + // 'status' => false, + // 'message' => 'Order does not exist', + // ]; + // } else { + // try { + // $order->delete(); + // $result = [ + // 'status' => true, + // 'message' => ' Delete successfully', + // ]; + // } catch (\Exception $e) { + // $result = [ + // 'status' => true, + // 'message' => 'Failed to delete order', + // 'error' => $e->getMessage() + // ]; + // } + // } + // return response()->json($result); + } + public function cancelled(Request $request, $id) + { + $data = $request->only(['status']); + try { + $order = Order::find($id); + $order->update($data); + $result = [ + 'status' => true, + 'msg' => 'Cancel success', + ]; + } catch (Exception $e) { + $result = [ + 'status' => false, + 'msg' => 'Cancel fail', + ]; + } + return response()->json($result); } } diff --git a/app/Http/Controllers/ProductsController.php b/app/Http/Controllers/ProductsController.php new file mode 100644 index 0000000..8e6c8b2 --- /dev/null +++ b/app/Http/Controllers/ProductsController.php @@ -0,0 +1,179 @@ +all(); + $orderBy = isset($params['orderBy']) ? $params['orderBy'] : 'created_at'; + $type = isset($params['type']) ? $params['type'] : 'desc'; + $products = Product::orderBy($orderBy, $type)->paginate(config('products.paginate')); + $selected = [ + 1 => (($orderBy == 'created_at') && ($type == 'desc')), + 2 => (($orderBy == 'price') && ($type == 'asc')), + 3 => (($orderBy == 'price') && ($type == 'desc')), + ]; + return view('products.index', ['products' => $products, 'selected' => $selected]); + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create() + { + + return view('products.create'); + + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $data = $request->only([ + 'category_id', + 'product_name', + 'price', + 'image', + 'quantity', + 'avg_rating', + 'description', + ]); + $uploaded = $this->upload($data['image']); + if (!$uploaded['status']) { + return back()->with('status', $uploaded['msg']); + } + $data['image'] = $uploaded['file_name']; + try { + $product = Product::create($data); + } catch (Exception $e) { + return back()->with('status', 'Create fail!'); + } + return redirect('products/' . $product->id)->with('status', 'Create success!'); + } + private function upload($file) + { + $destinationFolder = public_path() . "/" . config('products.image_path'); + try { + $fileName = $file->getClientOriginalName() . '_' . date('Ymd_His'); + $ext = $file->getClientOriginalExtension(); + if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { + $result = [ + 'status' => false, + 'msg' => 'Sorry, only JPG, JPEG, PNG & GIF files are allowed.', + ]; + } + // $mimeType = $file->getMimeType(); + // $realPath = $file->getRealPath(); + $file->move($destinationFolder, $fileName); + $result = [ + 'status' => true, + 'file_name' => $fileName, + ]; + } catch (Exception $e) { + $msg = $e->getMessage(); + $result = [ + 'status' => false, + 'msg' => $msg, + ]; + } + return $result; + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show($id) + { + $products = Product::find($id); + if (!$products) { + return back()->with('status', 'Product does not exist'); + } + + return view('products.show', ['product' => $products]); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + $products = Product::find($id); + if (!$products) { + return back()->with('status', 'Product does not exist'); + } + if ($products->id != auth()->id){ + return back()->with('status', 'You do not have permission'); + } + + return view('products.edit', ['product' => $products]); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + $data = $request->only(['category_id', 'product_name', 'price', 'quantity', 'image']); + + try { + $products = User::find($id); + $products->update($data); + } catch (Exception $e) { + return back()->with('status', 'Product update failed'); + } + + return redirect('products')->with('status', 'Product updated!'); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + try { + $products = User::find($id); + $products->delete(); + $result = [ + 'status' => true, + 'msg' => 'Delete success', + ]; + } catch (Exception $e) { + $result = [ + 'status' => false, + 'msg' => 'Delete fail', + ]; + } + + return response()->json($result); + } +} diff --git a/app/Http/Controllers/UserProfileController.php b/app/Http/Controllers/UserProfileController.php new file mode 100644 index 0000000..e69de29 diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index d346b06..6265ce5 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -13,6 +13,15 @@ class UsersController extends Controller * * @return \Illuminate\Http\Response */ + + public function index() + { + $users = DB::table('users')->paginate(5); + + return view('users.index', ['users' => $users]); + } + + public function index() { $users = User::all(); diff --git a/app/Order.php b/app/Order.php index 6614d47..d1958bc 100644 --- a/app/Order.php +++ b/app/Order.php @@ -12,6 +12,6 @@ class Order extends Model * @var array */ protected $fillable = [ - 'user_id', 'total_price', 'description', + 'user_id', 'total_price', 'description', 'status', ]; } diff --git a/app/Product.php b/app/Product.php new file mode 100644 index 0000000..d7dd7a5 --- /dev/null +++ b/app/Product.php @@ -0,0 +1,12 @@ +=7.0", + "symfony/debug": "^3|^4", + "symfony/finder": "^3|^4" + }, + "require-dev": { + "laravel/framework": "5.5.x" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facade" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "time": "2019-02-26T18:01:54+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "0.1", @@ -1102,6 +1170,67 @@ ], "time": "2019-02-01T08:50:36+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30e7d60937ee5f1320975ca9bc7bcdd44d500f07", + "reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "^1.0", + "symfony/var-dumper": "^2.6|^3.0|^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "time": "2017-12-15T11:13:46+00:00" + }, { "name": "monolog/monolog", "version": "1.24.0", diff --git a/config/app.php b/config/app.php index 57ee5b7..150b53c 100644 --- a/config/app.php +++ b/config/app.php @@ -1,7 +1,7 @@ [ + Barryvdh\Debugbar\ServiceProvider::class, + // JeroenNoten\LaravelAdminLte\ServiceProvider::class, + /* * Laravel Framework Service Providers... @@ -223,6 +226,8 @@ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, + 'Debugbar' => Barryvdh\Debugbar\Facade::class, + ], diff --git a/config/orders.php b/config/orders.php new file mode 100644 index 0000000..478edaa --- /dev/null +++ b/config/orders.php @@ -0,0 +1,6 @@ + 1, + 'delivering' => 2, + 'cancelled' => 3, +]; \ No newline at end of file diff --git a/config/products.php b/config/products.php new file mode 100644 index 0000000..51cc702 --- /dev/null +++ b/config/products.php @@ -0,0 +1,4 @@ + 'images/', +]; diff --git a/database/migrations/2019_03_01_130401_add_status_to_orders.php b/database/migrations/2019_03_01_130401_add_status_to_orders.php new file mode 100644 index 0000000..6a8f7b9 --- /dev/null +++ b/database/migrations/2019_03_01_130401_add_status_to_orders.php @@ -0,0 +1,32 @@ +integer('status'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('orders', function (Blueprint $table) { + $table->dropColumn('status'); + }); + } +} diff --git a/database/migrations/2019_03_07_130744_create_products_table.php b/database/migrations/2019_03_07_130744_create_products_table.php new file mode 100644 index 0000000..97b5a79 --- /dev/null +++ b/database/migrations/2019_03_07_130744_create_products_table.php @@ -0,0 +1,36 @@ +increments('id'); + $table->increments('category_id'); + $table->text('product_name'); + $table->integer('price'); + $table->integer('quantity'); + $table->text('image'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('products'); + } +} diff --git a/database/migrations/2019_03_19_120107_add_attribute_description_into_product_table.php b/database/migrations/2019_03_19_120107_add_attribute_description_into_product_table.php new file mode 100644 index 0000000..7aa2679 --- /dev/null +++ b/database/migrations/2019_03_19_120107_add_attribute_description_into_product_table.php @@ -0,0 +1,33 @@ +text('description'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('status'); + }); + } +} diff --git a/database/seeds/ProductsTableSeeder.php b/database/seeds/ProductsTableSeeder.php new file mode 100644 index 0000000..8e80ac1 --- /dev/null +++ b/database/seeds/ProductsTableSeeder.php @@ -0,0 +1,16 @@ +Dashboard +@stop + +@section('content') +
Welcome to this beautiful admin panel.
+@stop + + +@push('css') + +@push('js') \ No newline at end of file diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 05dfca9..89bd498 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -14,10 +14,154 @@ @endif - You are logged in! + Hello Baby <3 +This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+