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', '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')); $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', '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()) { if ($request->get('product_id') == $productId && Product::findOrFail($productId)->delete()) {
flash(trans('product.deleted'), 'success'); flash(trans('product.deleted'), 'success');

2
app/Http/Controllers/UnitsController.php

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

5
app/Unit.php

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

2
resources/lang/id/product.php

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

1
resources/lang/id/unit.php

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

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

@ -3,7 +3,10 @@
@section('title', trans('product.list')) @section('title', trans('product.list'))
@section('content') @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="row">
<div class="col-md-8"> <div class="col-md-8">
@ -36,13 +39,14 @@
<td class="text-right">{{ formatRp($product->cash_price) }}</td> <td class="text-right">{{ formatRp($product->cash_price) }}</td>
<td class="text-right">{{ formatRp($product->credit_price) }}</td> <td class="text-right">{{ formatRp($product->credit_price) }}</td>
<td class="text-center"> <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> </td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
<div class="panel-body">{!! str_replace('/?', '?', $products->appends(Request::except('page'))->render()) !!}</div>
</div> </div>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">

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

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

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

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

Loading…
Cancel
Save