diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php index 5632f5b..4a0671c 100644 --- a/app/Http/Controllers/Admin/CompanyController.php +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Company; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Validator; class CompanyController extends Controller { @@ -47,7 +49,7 @@ class CompanyController extends Controller */ public function show(Company $company) { - // + return view('admin.company.show', compact('company')); } /** @@ -58,7 +60,7 @@ class CompanyController extends Controller */ public function edit(Company $company) { - // + return view('admin.company.edit', compact('company')); } /** @@ -70,7 +72,27 @@ class CompanyController extends Controller */ public function update(Request $request, Company $company) { - // + $rules = [ + 'title' => 'required|min:3|max:255', + 'area_demo' => 'min:0|numeric', + 'workers' => 'min:0|numeric', + 'stock_area' => 'min:0|numeric', + 'name_equipment' => 'min:0|numeric', + ]; + + $messages = [ + 'required' => 'Поле не может быть пустым!', + ]; + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.company.show', ['company' => $company->id]) + ->withErrors($validator); + } else { + $params = $request->all(); + $company->update($params); + return redirect()->route('admin.company.show', ['company' => $company->id]); + } } /** diff --git a/app/Http/Controllers/Admin/NewsController.php b/app/Http/Controllers/Admin/NewsController.php index 1f5f847..c2bb247 100644 --- a/app/Http/Controllers/Admin/NewsController.php +++ b/app/Http/Controllers/Admin/NewsController.php @@ -58,6 +58,9 @@ class NewsController extends Controller $news->title = $request->title; $news->text = $request->text; $news->image = $request->file('image')->store('news', 'public'); + $news->author = $request->author; + $news->company = $request->company; + $news->status = $request->status; $news->save(); //$area->fotos()->save($foto_area); diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 0af6854..28f9e8c 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -12,19 +12,32 @@ use Symfony\Component\HttpFoundation\Session\Storage; class MainController extends Controller { // Главная страница - public function index() { + public function index(Request $request) { $banners = Banner::query()->orderBy('id')->get(); $category = Category::query()->where('parent_id', '>', '0')->orderBy('id')->get(); - $goods_new = Good::query()->where('new', '=', '1')->orderBy('id')->paginate(8); - $goods_stock = Good::query()->where('stock_count', '>', '0')->orderBy('id')->paginate(8); - $goods_demo = Good::query()->where('demo', '=', '1')->orderBy('id')->paginate(8); - $goods_way = Good::query()->where('way', '=', '1')->orderBy('id')->paginate(8); + if (isset($request->filter)) { + switch($request->filter) { + case 'news':$goods = Good::query()->where('new', '=', '1')->orderBy('id')->paginate(8); + break; + case 'stock':$goods = Good::query()->where('stock_count', '>', '0')->orderBy('id')->paginate(8); + break; + case 'demo':$goods = Good::query()->where('demo', '=', '1')->orderBy('id')->paginate(8); + break; + case 'way':$goods = Good::query()->where('way', '=', '1')->orderBy('id')->paginate(8); + break; + } + } else { + $goods = Good::query()->where('new', '=', '1')->orderBy('id')->paginate(8); + } + + if ($request->ajax()) { + return view('index_catalog', compact('goods')); + } - $news = News::query()->orderByDesc('id')->paginate(3); + $news = News::query()->where('status', '=', 'новость')->orderByDesc('id')->paginate(3); return view('index', - compact('banners', 'category', 'goods_new', 'goods_stock', - 'goods_demo', 'goods_way', 'news')); + compact('banners', 'category', 'goods', 'news')); } public function about_company() { @@ -34,6 +47,8 @@ class MainController extends Controller public function catalog(Request $request) { $items = Category::all(); $goods = Good::query(); + $articles = News::query()->where('status', '=', 'статья')->paginate(10); + $reviews = News::query()->where('status', '=', 'отзыв')->paginate(3); if (!empty($request->filter)) { $filter = json_decode($request->filter); @@ -56,21 +71,38 @@ class MainController extends Controller return view('catalog_ajax', compact('goods')); } - - $mf = Good::select('manufacturer')->distinct()->pluck('manufacturer'); - return view('catalog', compact('items', 'goods', 'mf')); + return view('catalog', compact('items', 'goods', 'mf', 'articles', 'reviews')); } - public function catalog_detail(Category $category) { + public function catalog_detail(Category $category, Request $request) { $items = Category::all(); $title = $category->name; - $goods = Good::query()->where('category_id', '=', $category->id) - ->orderByDesc('id')->paginate(6); - $mf = Good::select('manufacturer')->distinct()->where('category_id', '=', $category->id) - ->pluck('manufacturer'); + $goods = Good::query()->where('category_id', '=', $category->id); + + if (!empty($request->filter)) { + $filter = json_decode($request->filter); + if (is_array($filter)) + if (count($filter) > 0) + $goods = $goods->whereIn('manufacturer', $filter); + } + + if ($request->sort == 'count') { + $goods = $goods->orderByDesc('stock_count')->orderByDesc('id'); + } + + if ($request->sort == 'price') { + $goods = $goods->orderBy('price')->orderByDesc('id'); + } + + $goods = $goods->paginate(6); + + if ($request->ajax()) { + return view('catalog_ajax', compact('goods')); + } - return view('catalog_detail', compact('items', 'goods', 'title', 'mf')); + $mf = Good::select('manufacturer')->distinct()->where('category_id', '=', $category->id)->pluck('manufacturer'); + return view('catalog_detail', compact('items', 'category', 'goods', 'title', 'mf')); } public function good(Good $good) { diff --git a/app/Models/Company.php b/app/Models/Company.php index cffe058..1e81c4e 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model; class Company extends Model { use HasFactory; + + protected $fillable = ['title', 'text', 'area_demo', 'workers', 'stock_area', 'name_equipment']; } diff --git a/app/Models/News.php b/app/Models/News.php index c300081..4a4f468 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -9,5 +9,5 @@ class News extends Model { use HasFactory; - protected $fillable = ['title', 'image', 'text']; + protected $fillable = ['title', 'image', 'text', 'author', 'company', 'status']; } diff --git a/app/Providers/ComposerServiceProvider.php b/app/Providers/ComposerServiceProvider.php index 1e47b04..2fec28d 100644 --- a/app/Providers/ComposerServiceProvider.php +++ b/app/Providers/ComposerServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Models\Category; +use App\Models\Company; use App\Models\Good; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; @@ -44,6 +45,16 @@ class ComposerServiceProvider extends ServiceProvider $view->with(['items' => $items]); }); + $views = [ + 'layout.admin', + 'index', + 'company', + ]; + View::composer($views, + function($view) { + $company = Company::query()->where('id', '=', '1')->get(); + $view->with(['company' => $company]); + }); } diff --git a/resources/views/admin/company/edit.blade.php b/resources/views/admin/company/edit.blade.php new file mode 100644 index 0000000..bf17bc5 --- /dev/null +++ b/resources/views/admin/company/edit.blade.php @@ -0,0 +1,71 @@ +@extends('layout.admin', ['title' => 'Редактирование компании']) + +@section('content') +
{{ $company->title }}
{{ $company->text }}
{{ $company->area_demo }}
{{ $company->workers }}
{{ $company->stock_area }}
{{ $company->name_equipment }}
ID | Фото | Заголовок | +Статус | Дата создания | Действия | @@ -31,6 +32,7 @@ }?>{{ $new->title }} | +{{ $new->status }} | {{ $new->created_at }} |
---|