Skip to content

Commit

Permalink
Aplikasi E-Commerce Laravel 6 #7: Filter & Product Detail
Browse files Browse the repository at this point in the history
  • Loading branch information
makassarnetwork committed Nov 8, 2019
1 parent 6a3ee50 commit 6767f67
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 6 deletions.
15 changes: 13 additions & 2 deletions app/Http/Controllers/Ecommerce/FrontController.php
Expand Up @@ -18,7 +18,18 @@ public function index()
public function product()
{
$products = Product::orderBy('created_at', 'DESC')->paginate(12);
$categories = Category::with(['child'])->withCount(['child'])->getParent()->orderBy('name', 'ASC')->get();
return view('ecommerce.product', compact('products', 'categories'));
return view('ecommerce.product', compact('products'));
}

public function categoryProduct($slug)
{
$products = Category::where('slug', $slug)->first()->product()->orderBy('created_at', 'DESC')->paginate(12);
return view('ecommerce.product', compact('products'));
}

public function show($slug)
{
$product = Product::with(['category'])->where('slug', $slug)->first();
return view('ecommerce.show', compact('product'));
}
}
15 changes: 15 additions & 0 deletions app/Http/View/CategoryComposer.php
@@ -0,0 +1,15 @@
<?php

namespace App\Http\View;

use Illuminate\View\View;
use App\Category;

class CategoryComposer
{
public function compose(View $view)
{
$categories = Category::with(['child'])->withCount(['child'])->getParent()->orderBy('name', 'ASC')->get();
$view->with('categories', $categories);
}
}
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Expand Up @@ -3,6 +3,7 @@
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -23,6 +24,6 @@ public function register()
*/
public function boot()
{
//
View::composer('ecommerce.*', 'App\Http\View\CategoryComposer');
}
}
9 changes: 6 additions & 3 deletions resources/views/ecommerce/product.blade.php
Expand Up @@ -62,6 +62,9 @@
</div>
</div>
@empty
<div class="col-md-12">
<h3 class="text-center">Tidak ada produk</h3>
</div>
@endforelse
</div>
</div>
Expand All @@ -72,13 +75,13 @@
<h3>Kategori Produk</h3>
</div>
<div class="widgets_inner">
<ul class="list">
<ul class="list" >
@foreach ($categories as $category)
<li>
<a href="{{ $category->child_count > 0 ? '#':url('/category/' . $category->slug) }}">{{ $category->name }}</a>
<strong><a href="{{ url('/category/' . $category->slug) }}">{{ $category->name }}</a></strong>

@foreach ($category->child as $child)
<ul class="list">
<ul class="list" style="display: block">
<li>
<a href="{{ url('/category/' . $child->slug) }}">{{ $child->name }}</a>
</li>
Expand Down
122 changes: 122 additions & 0 deletions resources/views/ecommerce/show.blade.php
@@ -0,0 +1,122 @@
@extends('layouts.ecommerce')

@section('title')
<title>Jual {{ $product->name }}</title>
@endsection

@section('content')
<!--================Home Banner Area =================-->
<section class="banner_area">
<div class="banner_inner d-flex align-items-center">
<div class="container">
<div class="banner_content text-center">
<h2>{{ $product->name }}</h2>
<div class="page_link">
<a href="{{ url('/') }}">Home</a>
<a href="#">{{ $product->name }}</a>
</div>
</div>
</div>
</div>
</section>
<!--================End Home Banner Area =================-->

<div class="product_image_area">
<div class="container">
<div class="row s_product_inner">
<div class="col-lg-6">
<div class="s_product_img">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="{{ asset('storage/products/' . $product->image) }}" alt="{{ $product->name }}">
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-5 offset-lg-1">
<div class="s_product_text">
<h3>{{ $product->name }}</h3>
<h2>Rp {{ number_format($product->price) }}</h2>
<ul class="list">
<li>
<a class="active" href="#">
<span>Kategori</span> : {{ $product->category->name }}</a>
</li>
</ul>
<p></p>
<div class="product_count">
<label for="qty">Quantity:</label>
<input type="text" name="qty" id="sst" maxlength="12" value="1" title="Quantity:" class="input-text qty">
<button onclick="var result = document.getElementById('sst'); var sst = result.value; if( !isNaN( sst )) result.value++;return false;"
class="increase items-count" type="button">
<i class="lnr lnr-chevron-up"></i>
</button>
<button onclick="var result = document.getElementById('sst'); var sst = result.value; if( !isNaN( sst ) &amp;&amp; sst > 0 ) result.value--;return false;"
class="reduced items-count" type="button">
<i class="lnr lnr-chevron-down"></i>
</button>
</div>
<div class="card_area">
<a class="main_btn" href="#">Add to Cart</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!--================End Single Product Area =================-->

<!--================Product Description Area =================-->
<section class="product_description_area">
<div class="container">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active show" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Description</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Specification</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab" style="color: black">
{!! $product->description !!}
</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
<div class="table-responsive">
<table class="table">
<tbody>
<tr>
<td>
<h5>Berat</h5>
</td>
<td>
<h5>{{ $product->weight }} gr</h5>
</td>
</tr>
<tr>
<td>
<h5>Harga</h5>
</td>
<td>
<h5>Rp {{ number_format($product->price) }}</h5>
</td>
</tr>
<tr>
<td>
<h5>Kategori</h5>
</td>
<td>
<h5>{{ $product->category->name }}</h5>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<!--================End Product Description Area =================-->
@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Expand Up @@ -12,6 +12,8 @@
*/
Route::get('/', 'Ecommerce\FrontController@index')->name('front.index');
Route::get('/product', 'Ecommerce\FrontController@product')->name('front.product');
Route::get('/category/{slug}', 'Ecommerce\FrontController@categoryProduct')->name('front.category');
Route::get('/product/{slug}', 'Ecommerce\FrontController@show')->name('front.show_product');

Auth::routes();

Expand Down

0 comments on commit 6767f67

Please sign in to comment.