first upload all files
This commit is contained in:
40
Modules/Brand/Http/Controllers/Admin/BrandController.php
Normal file
40
Modules/Brand/Http/Controllers/Admin/BrandController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Brand\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Brand\Entities\Brand;
|
||||
use Modules\Admin\Traits\HasCrudActions;
|
||||
use Modules\Brand\Http\Requests\SaveBrandRequest;
|
||||
|
||||
class BrandController
|
||||
{
|
||||
use HasCrudActions;
|
||||
|
||||
/**
|
||||
* Model for the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Brand::class;
|
||||
|
||||
/**
|
||||
* Label of the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'brand::brands.brand';
|
||||
|
||||
/**
|
||||
* View path of the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewPath = 'brand::admin.brands';
|
||||
|
||||
/**
|
||||
* Form requests for the resource.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $validation = SaveBrandRequest::class;
|
||||
}
|
||||
21
Modules/Brand/Http/Controllers/BrandController.php
Normal file
21
Modules/Brand/Http/Controllers/BrandController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Brand\Http\Controllers;
|
||||
|
||||
use Modules\Brand\Entities\Brand;
|
||||
|
||||
class BrandController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('public.brands.index', [
|
||||
'brands' => Brand::with('files')->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
37
Modules/Brand/Http/Controllers/BrandProductController.php
Normal file
37
Modules/Brand/Http/Controllers/BrandProductController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Brand\Http\Controllers;
|
||||
|
||||
use Modules\Brand\Entities\Brand;
|
||||
use Modules\Product\Entities\Product;
|
||||
use Modules\Product\Filters\ProductFilter;
|
||||
use Modules\Product\Http\Controllers\ProductSearch;
|
||||
|
||||
class BrandProductController
|
||||
{
|
||||
use ProductSearch;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param string $slug
|
||||
* @param \Modules\Product\Entities\Product $model
|
||||
* @param \Modules\Product\Filters\ProductFilter $productFilter
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index($slug, Product $model, ProductFilter $productFilter)
|
||||
{
|
||||
request()->merge(['brand' => $slug]);
|
||||
|
||||
if (request()->expectsJson()) {
|
||||
return $this->searchProducts($model, $productFilter);
|
||||
}
|
||||
|
||||
$brand = Brand::findBySlug($slug);
|
||||
|
||||
return view('public.products.index', [
|
||||
'brandName' => $brand->name,
|
||||
'brandBanner' => $brand->banner->path,
|
||||
]);
|
||||
}
|
||||
}
|
||||
43
Modules/Brand/Http/Requests/SaveBrandRequest.php
Normal file
43
Modules/Brand/Http/Requests/SaveBrandRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Brand\Http\Requests;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Brand\Entities\Brand;
|
||||
use Modules\Core\Http\Requests\Request;
|
||||
|
||||
class SaveBrandRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Available attributes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $availableAttributes = 'brand::attributes';
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => ['required'],
|
||||
'slug' => $this->getSlugRules(),
|
||||
];
|
||||
}
|
||||
|
||||
private function getSlugRules()
|
||||
{
|
||||
$rules = $this->route()->getName() === 'admin.brands.update'
|
||||
? ['required']
|
||||
: ['sometimes'];
|
||||
|
||||
$slug = Brand::withoutGlobalScope('active')->where('id', $this->id)->value('slug');
|
||||
|
||||
$rules[] = Rule::unique('brands', 'slug')->ignore($slug, 'slug');
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user