Commit c0ef4387 by Francisco Salazar

validate slug, validate images

parent 0eeead57
......@@ -23,8 +23,9 @@ use Onestartup\Shop\Libs\Util;
use Onestartup\Shop\Requests\RequestProduct;
use Onestartup\Shop\Requests\RequestProductInfo;
use Onestartup\Shop\Payment\MP;
use Onestartup\Shop\Requests\RequestGallery;
use Onestartup\Shop\Payment\MP;
use PayPal\Api\Amount;
use PayPal\Api\Refund;
use PayPal\Api\Sale as SalePaypal;
......@@ -201,7 +202,7 @@ class AdminProductController extends Controller
}
public function storeGallery(Request $request, $product_id)
public function storeGallery(RequestGallery $request, $product_id)
{
$product = Product::find($product_id);
......@@ -247,11 +248,8 @@ class AdminProductController extends Controller
}
$product->cover = null;
$product->save();
$product->save();
//$gallery->delete();
return redirect()
->back()
->with('message_danger', 'Imagen eliminada correctamente');
......
......@@ -23,11 +23,17 @@ class RequestCategory extends FormRequest
*/
public function rules()
{
if ($this->get("_method") == "PUT" || $this->get("_method") == "PATCH"){
$slug = 'required|max:255|unique:product_categories_shop,slug,'.$this->route("category");
}else{
$slug = 'required|max:255|unique:product_categories_shop,slug';
}
return [
'name' => 'required|max:355',
'slug' => 'required|max:255',
'slug' => $slug,
'description'=> 'max:455',
'active' => 'required|boolean'
'active' => 'required|boolean',
'portada' => 'image'
];
}
}
\ No newline at end of file
<?php
namespace Onestartup\Shop\Requests;
use Illuminate\Foundation\Http\FormRequest;
class RequestGallery extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'file.*' => 'image'
];
}
}
\ No newline at end of file
......@@ -23,9 +23,14 @@ class RequestProduct extends FormRequest
*/
public function rules()
{
if ($this->get("_method") == "PUT" || $this->get("_method") == "PATCH"){
$slug = 'required|max:455|unique:products_shop,slug,'.$this->route("product");
}else{
$slug = 'required|max:455|unique:products_shop,slug';
}
return [
'name' => 'required|max:355',
'slug' => 'required|max:455',
'slug' => $slug,
'description' => 'required',
'active' => 'required|boolean',
'publication_date' => 'required',
......
......@@ -50,7 +50,7 @@
<div class='modal-footer'>
<button class='btn dark p-x-md' data-dismiss='modal' type='button'>Cerrar</button>
@if($category->cover != null)
{!! Form::open(['route'=> ['delete.cover.category.shop',$category->id],'method'=>'DELETE'])!!}
{!! Form::open(['route'=> ['admin-shop-category.delete.cover',$category->id],'method'=>'DELETE'])!!}
<button class='btn btn-danger button-mb' onclick="return confirm('¿Estás seguro de eliminar este elemento?');" type='submit'>
<i class='fas fa-trash-alt icon-special-size'>
Eliminar
......
......@@ -120,41 +120,35 @@
</div>
</div>
</div><!-- end tab-3 -->
</div>
</div>
</div>
<!-- .modal nuevo contrato -->
<div class='modal fade' data-backdrop='true' id='ver'>
<div class='modal-dialog modal-lg'>
<div class='modal-content box-shadow-z3'>
<div class='modal-body text-center p-lg'>
@if ($product->cover == null)
<h4>No hay imagen asignada.</h4>
@else
<img class='image-modal-preview' src="{{asset('storage/'.$product->cover)}}">
@endif
</div>
<div class='modal-footer'>
<button class='btn dark p-x-md' data-dismiss='modal' type='button'>Cerrar</button>
@if($product->cover != null)
{!! Form::open(['route'=> ['admin-shop-product.delete.cover',$product->id],'method'=>'DELETE'])!!}
<button class='btn btn-danger button-mb' onclick="return confirm('¿Estás seguro de eliminar este elemento?');" type='submit'>
<i class='fas fa-trash-alt icon-special-size'></i>
Eliminar
</button>
{!! Form::close()!!}
@endif
</div>
<!-- .modal nuevo contrato -->
<div class='modal fade' data-backdrop='true' id='ver'>
<div class='modal-dialog modal-lg'>
<div class='modal-content box-shadow-z3'>
<div class='modal-body text-center p-lg'>
@if ($product->cover == null)
<h4>No hay imagen asignada.</h4>
@else
<img class='image-modal-preview' src="{{asset('storage/'.$product->cover)}}">
@endif
</div>
<div class='modal-footer'>
<button class='btn dark p-x-md' data-dismiss='modal' type='button'>Cerrar</button>
@if($product->cover != null)
{!! Form::open(['route'=> ['admin-shop-product.delete.cover',$product->id],'method'=>'DELETE'])!!}
<button class='btn btn-danger button-mb' onclick="return confirm('¿Estás seguro de eliminar este elemento?');" type='submit'>
<i class='fas fa-trash-alt icon-special-size'></i>
Eliminar
</button>
{!! Form::close()!!}
@endif
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-content -->
</div>
</div>
@endsection
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment