Browse Source

Added delete a product within search query

pull/4/head
Nafies Luthfi 9 years ago
parent
commit
45b9b88d58
  1. 4
      app/Http/Controllers/ProductsController.php
  2. 11
      resources/views/products/partials/forms.blade.php
  3. 22
      tests/Feature/ManageProductsTest.php

4
app/Http/Controllers/ProductsController.php

@ -62,9 +62,11 @@ class ProductsController extends Controller
'product_id' => 'required|exists:products,id',
]);
$routeParam = $request->only('q');
if ($request->get('product_id') == $productId && Product::findOrFail($productId)->delete()) {
flash(trans('product.deleted'), 'success');
return redirect()->route('products.index');
return redirect()->route('products.index', $routeParam);
}
flash(trans('product.undeleted'), 'error');

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

@ -20,7 +20,9 @@
<div class="col-md-6">{!! FormField::price('cash_price', ['label' => trans('product.cash_price'), 'required' => true]) !!}</div>
<div class="col-md-6">{!! FormField::price('credit_price', ['label' => trans('product.credit_price')]) !!}</div>
</div>
{{ Form::hidden('q', request('q')) }}
@if (request('q'))
{{ Form::hidden('q', request('q')) }}
@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() !!}
@ -40,7 +42,12 @@
{{ trans('product.delete_confirm') }}
</div>
<div class="panel-footer">
{!! FormField::delete(['route'=>['products.destroy',$editableProduct->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['product_id'=>$editableProduct->id]) !!}
{!! FormField::delete(['route'=>['products.destroy',$editableProduct->id]], trans('app.delete_confirm_button'), [
'class'=>'btn btn-danger'
], [
'product_id'=>$editableProduct->id,
'q' => request('q')
]) !!}
{{ link_to_route('products.index', trans('app.cancel'), Request::only('q'), ['class' => 'btn btn-default']) }}
</div>
</div>

22
tests/Feature/ManageProductsTest.php

@ -151,4 +151,26 @@ class ManageProductsTest extends BrowserKitTestCase
'id' => $product->id
]);
}
/** @test */
public function user_can_delete_a_product_within_search_query()
{
$this->loginAsUser();
$product = factory(Product::class)->create(['name' => 'Product 123']);
$this->visit(route('products.index', ['q' => '123']));
$this->click('del-product-' . $product->id);
$this->seePageIs(route('products.index', ['action' => 'delete','id' => $product->id, 'q' => '123']));
$this->seeInDatabase('products', [
'id' => $product->id
]);
$this->press(trans('app.delete_confirm_button'));
$this->seePageIs(route('products.index', ['q' => '123']));
$this->dontSeeInDatabase('products', [
'id' => $product->id
]);
}
}
Loading…
Cancel
Save