Browse Source

Included page query string on product update and delete redirection

Added unit products_count column on unit index page table
Added product total on product index page title
pull/4/head
Nafies Luthfi 9 years ago
parent
commit
e70b1f88c6
  1. 4
      app/Http/Controllers/ProductsController.php
  2. 2
      app/Http/Controllers/UnitsController.php
  3. 5
      app/Unit.php
  4. 2
      resources/lang/id/product.php
  5. 1
      resources/lang/id/unit.php
  6. 10
      resources/views/products/index.blade.php
  7. 6
      resources/views/products/partials/forms.blade.php
  8. 3
      resources/views/units/index.blade.php

4
app/Http/Controllers/ProductsController.php

@ -50,7 +50,7 @@ class ProductsController extends Controller
'credit_price' => 'nullable|numeric',
]);
$routeParam = $request->only('q');
$routeParam = $request->only('page','q');
$product = Product::findOrFail($productId)->update($request->only('name','cash_price','credit_price','unit_id'));
@ -65,7 +65,7 @@ class ProductsController extends Controller
'product_id' => 'required|exists:products,id',
]);
$routeParam = $request->only('q');
$routeParam = $request->only('page','q');
if ($request->get('product_id') == $productId && Product::findOrFail($productId)->delete()) {
flash(trans('product.deleted'), 'success');

2
app/Http/Controllers/UnitsController.php

@ -10,7 +10,7 @@ class UnitsController extends Controller
public function index(Request $request)
{
$editableUnit = null;
$units = Unit::all();
$units = Unit::withCount('products')->get();
if (in_array($request->get('action'), ['edit','delete']) && $request->has('id'))
$editableUnit = Unit::find($request->get('id'));

5
app/Unit.php

@ -8,4 +8,9 @@ class Unit extends Model
{
protected $table = 'product_units';
protected $fillable = ['name'];
public function products()
{
return $this->hasMany(Product::class);
}
}

2
resources/lang/id/product.php

@ -2,7 +2,7 @@
return [
// Labels
'master' => 'Produk',
'product' => 'Produk',
'list' => 'Daftar Produk',
'search' => 'Cari Produk',
'not_found' => 'Produk tidak ditemukan',

1
resources/lang/id/unit.php

@ -5,6 +5,7 @@ return [
'unit' => 'Satuan',
'list' => 'Daftar Satuan',
'empty' => 'Belum ada Satuan',
'products_count' => 'Jumlah Produk',
'back_to_index' => 'Kembali ke daftar Satuan',
// Actions

10
resources/views/products/index.blade.php

@ -3,7 +3,10 @@
@section('title', trans('product.list'))
@section('content')
<h3 class="page.header">{{ trans('product.list') }}</h3>
<h3 class="page-header">
{{ trans('product.list') }}
<small>{{ trans('app.total') }} : {{ $products->total() }} {{ trans('product.product') }}</small>
</h3>
<div class="row">
<div class="col-md-8">
@ -36,13 +39,14 @@
<td class="text-right">{{ formatRp($product->cash_price) }}</td>
<td class="text-right">{{ formatRp($product->credit_price) }}</td>
<td class="text-center">
{!! link_to_route('products.index', trans('app.edit'), ['action' => 'edit', 'id' => $product->id] + Request::only('q'), ['id' => 'edit-product-' . $product->id]) !!} |
{!! link_to_route('products.index', trans('app.delete'), ['action' => 'delete', 'id' => $product->id] + Request::only('q'), ['id' => 'del-product-' . $product->id]) !!}
{!! link_to_route('products.index', trans('app.edit'), ['action' => 'edit', 'id' => $product->id] + Request::only('page','q'), ['id' => 'edit-product-' . $product->id]) !!} |
{!! link_to_route('products.index', trans('app.delete'), ['action' => 'delete', 'id' => $product->id] + Request::only('page','q'), ['id' => 'del-product-' . $product->id]) !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="panel-body">{!! str_replace('/?', '?', $products->appends(Request::except('page'))->render()) !!}</div>
</div>
</div>
<div class="col-md-4">

6
resources/views/products/partials/forms.blade.php

@ -26,6 +26,9 @@
@if (request('q'))
{{ Form::hidden('q', request('q')) }}
@endif
@if (request('page'))
{{ Form::hidden('page', request('page')) }}
@endif
{!! Form::submit(trans('product.update'), ['class' => 'btn btn-success']) !!}
{{ link_to_route('products.index', trans('app.cancel'), Request::only('q'), ['class' => 'btn btn-default']) }}
{!! Form::close() !!}
@ -50,7 +53,8 @@
'class'=>'btn btn-danger'
], [
'product_id'=>$editableProduct->id,
'q' => request('q')
'page' => request('page'),
'q' => request('q'),
]) !!}
{{ link_to_route('products.index', trans('app.cancel'), Request::only('q'), ['class' => 'btn btn-default']) }}
</div>

3
resources/views/units/index.blade.php

@ -3,6 +3,7 @@
@section('title', trans('unit.list'))
@section('content')
<h3 class="page-header">{{ trans('unit.list') }}</h3>
<div class="row">
<div class="col-md-8">
@ -12,6 +13,7 @@
<tr>
<th class="text-center">{{ trans('app.table_no') }}</th>
<th>{{ trans('unit.name') }}</th>
<th class="text-center">{{ trans('unit.products_count') }}</th>
<th class="text-center">{{ trans('app.action') }}</th>
</tr>
</thead>
@ -20,6 +22,7 @@
<tr>
<td class="text-center">{{ 1 + $key }}</td>
<td>{{ $unit->name }}</td>
<td class="text-center">{{ $unit->products_count }}</td>
<td class="text-center">
{!! link_to_route('units.index', trans('app.edit'), ['action' => 'edit', 'id' => $unit->id], ['id' => 'edit-unit-' . $unit->id]) !!} |
{!! link_to_route('units.index', trans('app.delete'), ['action' => 'delete', 'id' => $unit->id], ['id' => 'del-unit-' . $unit->id]) !!}

Loading…
Cancel
Save