Commit 319a9b7d by Francisco Salazar

validate slug, validate images, validate resources

parent 3c25b478
......@@ -13,6 +13,8 @@ use Onestartup\ProductResource\Model\ProductResource as Product;
use Onestartup\ProductResource\Model\ExtraFieldResource as Extra;
use Onestartup\ProductResource\Requests\RequestProduct;
use Onestartup\ProductResource\Requests\RequestGallery;
use Onestartup\ProductResource\Requests\RequestResource;
class AdminProductController extends Controller
{
......@@ -160,7 +162,7 @@ class AdminProductController extends Controller
}
public function storeGallery(Request $request, $product_id)
public function storeGallery(RequestGallery $request, $product_id)
{
$product = Product::find($product_id);
......@@ -199,7 +201,7 @@ class AdminProductController extends Controller
}
public function storeResource(Request $request, $product_id)
public function storeResource(RequestResource $request, $product_id)
{
$product = Product::find($product_id);
......
......@@ -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_resource,slug,'.$this->route("category");
}else{
$slug = 'required|max:255|unique:product_categories_resource,slug';
}
return [
'name' => 'required|max:355',
'slug' => 'required|max:255',
'slug' => $slug,
'description'=> 'max:455',
'active' => 'required'
'active' => 'required',
'portada' => 'image'
];
}
}
\ No newline at end of file
<?php
namespace Onestartup\ProductResource\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_resource,slug,'.$this->route("product");
}else{
$slug = 'required|max:455|unique:products_resource,slug';
}
return [
'name' => 'required|max:355',
'slug' => 'required|max:455',
'slug' => $slug,
'description'=> 'required',
'active' => 'required|boolean',
'publication_date' => 'required',
......@@ -39,7 +44,8 @@ class RequestProduct extends FormRequest
'extra8' => 'max:455',
'extra9' => 'max:455',
'extra10' => 'max:455',
'category_id' => 'required|numeric'
'category_id' => 'required|numeric',
'cover' => 'image'
];
}
}
\ No newline at end of file
<?php
namespace Onestartup\ProductResource\Requests;
use Illuminate\Foundation\Http\FormRequest;
class RequestResource 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.*' => 'mimes:pdf,doc,docx,xls,xlsx,ppt,pptx'
];
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
Route::resource('admin/product_resources/category', 'Onestartup\ProductResource\Controller\CategoryController', ['as'=>'admin.product_resources']);
Route::delete('delete/cover/category/product/{id}', 'Onestartup\ProductResource\Controller\CategoryController@deleteCover')
Route::delete('delete/cover/category/product_resource/{id}', 'Onestartup\ProductResource\Controller\CategoryController@deleteCover')
->name('delete.cover.category.product_resources');
Route::get('admin/product_resources/datatable', 'Onestartup\ProductResource\Controller\AdminProductController@getProducts')
......
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