diff --git a/src/ProductServiceProvider.php b/src/ProductServiceProvider.php index 886ea61..a6eb04c 100644 --- a/src/ProductServiceProvider.php +++ b/src/ProductServiceProvider.php @@ -32,6 +32,11 @@ class ProductServiceProvider extends ServiceProvider __DIR__.'/views/public' => resource_path('views/vendor/onestartup/product'), ]); + // Allow your user to publish the config + $this->publishes([ + __DIR__.'/config/product.php' => config_path('product.php'), + ], 'config'); + } @@ -46,6 +51,6 @@ class ProductServiceProvider extends ServiceProvider $this->app->make('Onestartup\Product\Controller\AdminProductController'); $this->app->make('Onestartup\Product\Controller\CategoryController'); $this->app->make('Onestartup\Product\Controller\ProductController'); - + $this->mergeConfigFrom( __DIR__.'/config/product.php', 'product'); } } diff --git a/src/config/product.php b/src/config/product.php new file mode 100644 index 0000000..33bdaf2 --- /dev/null +++ b/src/config/product.php @@ -0,0 +1,23 @@ +<?php + +return [ + "slug_products" => "productos", + "slug_category" => "categoria", + "slug_subcategory" => "subcategoria", + + "product-index" => [ + "pagination" => 25, + "otros" => 6, + ], + "product-show" => [ + "otros" => 6, + ], + "product-bycategory" => [ + "pagination" => 15, + "otros" => 6 + ], + "product-bysubcategory" => [ + "pagination" => 15, + "otros" => 6 + ], +]; \ No newline at end of file diff --git a/src/controllers/ProductController.php b/src/controllers/ProductController.php index 98af7ad..a75afc2 100644 --- a/src/controllers/ProductController.php +++ b/src/controllers/ProductController.php @@ -17,12 +17,12 @@ class ProductController extends Controller if(isset($request->category)){ $category = Category::where('slug', $request->category)->first(); - $products = $category->products()->where('active', true)->paginate(15); + $products = $category->products()->where('active', true)->paginate(config("product.product-index.")); } else { - $products = Product::where('active', true)->paginate(25); + $products = Product::where('active', true)->paginate(config("product.product-index.pagination")); } - $otros = Product::where('active', true)->inRandomOrder()->take(3)->get(); + $otros = Product::where('active', true)->inRandomOrder()->take(config("product.product-index.otros"))->get(); $categories = Category::where('active', true)->get(); return view('product-public::list') @@ -36,7 +36,7 @@ class ProductController extends Controller { $product = Product::where('slug',$slug)->first(); - $otros = $product->category->products()->where('active', true)->take(3)->get(); + $otros = $product->category->products()->where('active', true)->where("id", "<>", $product->id)->inRandomOrder()->take(config("product.product-show.otros"))->get(); $categories = Category::all(); @@ -60,9 +60,9 @@ class ProductController extends Controller public function byCategory($category_slug) { $category = Category::where('slug', $category_slug)->first(); - $products = $category->products()->where('active', true)->paginate(15); + $products = $category->products()->where('active', true)->paginate(config("product.product-bycategory.pagination")); - $otros = Product::where('active', true)->inRandomOrder()->take(3)->get(); + $otros = Product::where('active', true)->inRandomOrder()->take(config("product.product-bycategory.otros"))->get(); $categories = Category::where('active', true)->get(); return view('product-public::category') @@ -77,9 +77,9 @@ class ProductController extends Controller //return $category_slug . " " .$subcategory_slug; $category = Category::where('slug', $category_slug)->first(); $subcategory = $category->subcategories->where('slug', $subcategory_slug)->first(); - $products = $subcategory->products()->where('active', true)->paginate(15); + $products = $subcategory->products()->where('active', true)->paginate(config("product.product-bysubcategory.pagination")); - $otros = Product::where('active', true)->inRandomOrder()->take(3)->get(); + $otros = Product::where('active', true)->inRandomOrder()->take(config("product.product-bycategory.otros"))->get(); $categories = Category::where('active', true)->get(); $subcategories = $category->subcategories()->where('active' ,true)->get(); diff --git a/src/routes.php b/src/routes.php index 08a8f49..e71f62d 100644 --- a/src/routes.php +++ b/src/routes.php @@ -35,15 +35,15 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){ }); Route::group(['middleware' => ['web']], function(){ - Route::get(env('SLUG_PRODUCTS').'/{slug}', 'Onestartup\Product\Controller\ProductController@show')->name('show.product'); + Route::get(config("product.slug_products").'/{slug}', 'Onestartup\Product\Controller\ProductController@show')->name('show.product'); - Route::get(env('SLUG_PRODUCTS'), 'Onestartup\Product\Controller\ProductController@index')->name('main.product'); + Route::get(config("product.slug_products"), 'Onestartup\Product\Controller\ProductController@index')->name('main.product'); - Route::get(env('SLUG_PRODUCTS_CATEGORY').'/{slug_category}', + Route::get(config("product.slug_category").'/{slug_category}', 'Onestartup\Product\Controller\ProductController@byCategory') ->name('category.product'); - Route::get(env('SLUG_PRODUCTS_CATEGORY').'/{slug_category}/{slug_subcategory}', + Route::get(config("product.slug_category").'/{slug_category}/{slug_subcategory}', 'Onestartup\Product\Controller\ProductController@bySubCategory') ->name('subcategory.product'); });