Commit 6eff6bf11b34d00d6952359357d9727fe5737383

Authored by Андрей Ларионов
1 parent c5118e5f36
Exists in master

Админка сайта категории, баннеры, новости, проекты

Showing 26 changed files with 777 additions and 30 deletions Side-by-side Diff

app/Http/Controllers/Admin/BannerController.php
... ... @@ -84,7 +84,7 @@ class BannerController extends Controller
84 84 */
85 85 public function edit(Banner $banner)
86 86 {
87   - return view('admin.banners.edit', compact($banner));
  87 + return view('admin.banners.edit', compact('banner'));
88 88 }
89 89  
90 90 /**
... ... @@ -97,16 +97,19 @@ class BannerController extends Controller
97 97 public function update(Request $request, Banner $banner)
98 98 {
99 99 $rules = [
100   - 'image' => 'required|min:3|max:10000',
101 100 'title' => 'required|min:3|max:255'
102 101 ];
  102 +
  103 + if (empty($banner->image)) {
  104 + $rules['image'] = 'required|min:3|max:10000';
  105 + }
103 106 $messages = [
104 107 'required' => 'Поле не может быть пустым!',
105 108 ];
106 109 $validator = Validator::make($request->all(), $rules, $messages);
107 110  
108 111 if ($validator->fails()) {
109   - return redirect()->route('admin.banner.edit')
  112 + return redirect()->route('admin.banner.edit', ['banner' => $banner->id])
110 113 ->withErrors($validator);
111 114 } else {
112 115 $params = $request->all();
... ... @@ -132,7 +135,7 @@ class BannerController extends Controller
132 135 if (!empty($banner->image)) {
133 136 Storage::delete($banner->image);
134 137 }
135   - $image->delete();
  138 + $banner->delete();
136 139 return redirect()->route('admin.banner.index');
137 140 }
138 141 }
app/Http/Controllers/Admin/CategoryController.php
... ... @@ -3,8 +3,10 @@
3 3 namespace App\Http\Controllers\Admin;
4 4  
5 5 use App\Http\Controllers\Controller;
  6 +use App\Http\Requests\CategoryRequest;
6 7 use App\Models\Category;
7 8 use Illuminate\Http\Request;
  9 +use Illuminate\Support\Facades\Storage;
8 10  
9 11 class CategoryController extends Controller
10 12 {
... ... @@ -15,7 +17,8 @@ class CategoryController extends Controller
15 17 */
16 18 public function index()
17 19 {
18   - //
  20 + $categories = Category::query()->orderBy('id')->paginate(5);
  21 + return view('admin.category.index', compact('categories'));
19 22 }
20 23  
21 24 /**
... ... @@ -25,7 +28,7 @@ class CategoryController extends Controller
25 28 */
26 29 public function create()
27 30 {
28   - //
  31 + return view('admin.category.create');
29 32 }
30 33  
31 34 /**
... ... @@ -34,9 +37,16 @@ class CategoryController extends Controller
34 37 * @param \Illuminate\Http\Request $request
35 38 * @return \Illuminate\Http\Response
36 39 */
37   - public function store(Request $request)
  40 + public function store(CategoryRequest $request)
38 41 {
39   - //
  42 + $params = $request->all();
  43 +
  44 + if ($request->has('image')) {
  45 + $params['image'] = $request->file('image')->store('category', 'public');
  46 + }
  47 +
  48 + Category::create($params);
  49 + return redirect()->route('admin.category.index');
40 50 }
41 51  
42 52 /**
... ... @@ -58,7 +68,7 @@ class CategoryController extends Controller
58 68 */
59 69 public function edit(Category $category)
60 70 {
61   - //
  71 + return view('admin.category.edit', compact('category'));
62 72 }
63 73  
64 74 /**
... ... @@ -70,7 +80,17 @@ class CategoryController extends Controller
70 80 */
71 81 public function update(Request $request, Category $category)
72 82 {
73   - //
  83 + $params = $request->all();
  84 +
  85 + if ($request->has('image')) {
  86 + Storage::delete($category->image);
  87 + $params['image'] = $request->file('image')->store('category', 'public');
  88 + } else {
  89 + if (!empty($category->image)) $params['image'] = $category->image;
  90 + }
  91 +
  92 + $category->update($params);
  93 + return redirect()->route('admin.category.index');
74 94 }
75 95  
76 96 /**
... ... @@ -81,6 +101,10 @@ class CategoryController extends Controller
81 101 */
82 102 public function destroy(Category $category)
83 103 {
84   - //
  104 + if (!empty($category->image)) {
  105 + Storage::delete($category->image);
  106 + }
  107 + $category->delete();
  108 + return redirect()->route('admin.category.index');
85 109 }
86 110 }
app/Http/Controllers/Admin/NewsController.php
... ... @@ -4,7 +4,10 @@ namespace App\Http\Controllers\Admin;
4 4  
5 5 use App\Http\Controllers\Controller;
6 6 use App\Models\News;
  7 +use Illuminate\Database\Eloquent\Model;
7 8 use Illuminate\Http\Request;
  9 +use Illuminate\Support\Facades\Storage;
  10 +use Illuminate\Support\Facades\Validator;
8 11  
9 12 class NewsController extends Controller
10 13 {
... ... @@ -15,7 +18,8 @@ class NewsController extends Controller
15 18 */
16 19 public function index()
17 20 {
18   - //
  21 + $news = News::query()->orderBy('id')->paginate(5);
  22 + return view('admin.news.index', compact('news'));
19 23 }
20 24  
21 25 /**
... ... @@ -25,7 +29,7 @@ class NewsController extends Controller
25 29 */
26 30 public function create()
27 31 {
28   - //
  32 + return view('admin.news.create');
29 33 }
30 34  
31 35 /**
... ... @@ -36,7 +40,29 @@ class NewsController extends Controller
36 40 */
37 41 public function store(Request $request)
38 42 {
39   - //
  43 + $rules = [
  44 + 'image' => 'required|min:3|max:10000',
  45 + 'title' => 'required|min:3|max:255',
  46 + ];
  47 + $messages = [
  48 + 'required' => 'Поле не может быть пустым!',
  49 + ];
  50 + $validator = Validator::make($request->all(), $rules, $messages);
  51 +
  52 + if ($validator->fails()) {
  53 + return redirect()->route('admin.news.create')
  54 + ->withErrors($validator);
  55 + } else {
  56 +
  57 + $news = new News();
  58 + $news->title = $request->title;
  59 + $news->text = $request->text;
  60 + $news->image = $request->file('image')->store('news', 'public');
  61 + $news->save();
  62 +
  63 + //$area->fotos()->save($foto_area);
  64 + return redirect()->route('admin.news.index');
  65 + }
40 66 }
41 67  
42 68 /**
... ... @@ -58,7 +84,7 @@ class NewsController extends Controller
58 84 */
59 85 public function edit(News $news)
60 86 {
61   - //
  87 + return view('admin.news.edit', compact('news'));
62 88 }
63 89  
64 90 /**
... ... @@ -70,7 +96,32 @@ class NewsController extends Controller
70 96 */
71 97 public function update(Request $request, News $news)
72 98 {
73   - //
  99 + $rules = [
  100 + 'title' => 'required|min:3|max:255'
  101 + ];
  102 +
  103 + if (empty($news->image)) {
  104 + $rules['image'] = 'required|min:3|max:10000';
  105 + }
  106 + $messages = [
  107 + 'required' => 'Поле не может быть пустым!',
  108 + ];
  109 + $validator = Validator::make($request->all(), $rules, $messages);
  110 +
  111 + if ($validator->fails()) {
  112 + return redirect()->route('admin.news.edit', ['news' => $news->id])
  113 + ->withErrors($validator);
  114 + } else {
  115 + $params = $request->all();
  116 + unset($params['image']);
  117 + if ($request->has('image')) {
  118 + Storage::delete($news->image);
  119 + $params['image'] = $request->file('image')->store('news', 'public');
  120 + }
  121 +
  122 + $news->update($params);
  123 + return redirect()->route('admin.news.index');
  124 + }
74 125 }
75 126  
76 127 /**
... ... @@ -81,6 +132,10 @@ class NewsController extends Controller
81 132 */
82 133 public function destroy(News $news)
83 134 {
84   - //
  135 + if (!empty($news->image)) {
  136 + Storage::delete($news->image);
  137 + }
  138 + $news->delete();
  139 + return redirect()->route('admin.news.index');
85 140 }
86 141 }
app/Http/Controllers/Admin/ProjectController.php
... ... @@ -4,7 +4,10 @@ namespace App\Http\Controllers\Admin;
4 4  
5 5 use App\Http\Controllers\Controller;
6 6 use App\Models\Project;
  7 +use Illuminate\Database\Eloquent\Model;
7 8 use Illuminate\Http\Request;
  9 +use Illuminate\Support\Facades\Storage;
  10 +use Illuminate\Support\Facades\Validator;
8 11  
9 12 class ProjectController extends Controller
10 13 {
... ... @@ -15,7 +18,8 @@ class ProjectController extends Controller
15 18 */
16 19 public function index()
17 20 {
18   - //
  21 + $projects = Project::query()->orderBy('id')->paginate(5);
  22 + return view('admin.projects.index', compact('projects'));
19 23 }
20 24  
21 25 /**
... ... @@ -25,7 +29,7 @@ class ProjectController extends Controller
25 29 */
26 30 public function create()
27 31 {
28   - //
  32 + return view('admin.projects.create');
29 33 }
30 34  
31 35 /**
... ... @@ -36,7 +40,33 @@ class ProjectController extends Controller
36 40 */
37 41 public function store(Request $request)
38 42 {
39   - //
  43 + $rules = [
  44 + 'image' => 'required|min:3|max:10000',
  45 + 'title' => 'required|min:3|max:255',
  46 + 'customer' => 'required|min:3|max:255',
  47 + 'date_project' => 'required|min:3|max:255|date_format:d.m.Y',
  48 + ];
  49 + $messages = [
  50 + 'required' => 'Поле не может быть пустым!',
  51 + 'date' => 'Поле должно быть формата дата',
  52 + ];
  53 + $validator = Validator::make($request->all(), $rules, $messages);
  54 +
  55 + if ($validator->fails()) {
  56 + return redirect()->route('admin.project.create')
  57 + ->withErrors($validator);
  58 + } else {
  59 +
  60 + $Project = new Project();
  61 + $Project->title = $request->title;
  62 + $Project->customer = $request->customer;
  63 + $Project->date_project = date("Y-m-d", strtotime($request->date_project));
  64 + $Project->image = $request->file('image')->store('project', 'public');
  65 + $Project->save();
  66 +
  67 + //$area->fotos()->save($foto_area);
  68 + return redirect()->route('admin.project.index');
  69 + }
40 70 }
41 71  
42 72 /**
... ... @@ -58,7 +88,7 @@ class ProjectController extends Controller
58 88 */
59 89 public function edit(Project $project)
60 90 {
61   - //
  91 + return view('admin.projects.edit', compact('project'));
62 92 }
63 93  
64 94 /**
... ... @@ -70,7 +100,35 @@ class ProjectController extends Controller
70 100 */
71 101 public function update(Request $request, Project $project)
72 102 {
73   - //
  103 + $rules = [
  104 + 'title' => 'required|min:3|max:255',
  105 + 'customer' => 'required|min:3|max:255',
  106 + 'date_project' => 'required|min:3|max:255|date_format:d.m.Y',
  107 + ];
  108 +
  109 + if (empty($project->image)) {
  110 + $rules['image'] = 'required|min:3|max:10000';
  111 + }
  112 + $messages = [
  113 + 'required' => 'Поле не может быть пустым!',
  114 + ];
  115 +
  116 + $validator = Validator::make($request->all(), $rules, $messages);
  117 +
  118 + if ($validator->fails()) {
  119 + return redirect()->route('admin.project.edit', ['project' => $project->id])
  120 + ->withErrors($validator);
  121 + } else {
  122 + $params = $request->all();
  123 + unset($params['image']);
  124 + if ($request->has('image')) {
  125 + Storage::delete($project->image);
  126 + $params['image'] = $request->file('image')->store('project', 'public');
  127 + }
  128 +
  129 + $project->update($params);
  130 + return redirect()->route('admin.project.index');
  131 + }
74 132 }
75 133  
76 134 /**
... ... @@ -81,6 +139,10 @@ class ProjectController extends Controller
81 139 */
82 140 public function destroy(Project $project)
83 141 {
84   - //
  142 + if (!empty($project->image)) {
  143 + Storage::delete($project->image);
  144 + }
  145 + $project->delete();
  146 + return redirect()->route('admin.project.index');
85 147 }
86 148 }
app/Http/Requests/CategoryRequest.php
... ... @@ -0,0 +1,51 @@
  1 +<?php
  2 +
  3 +namespace App\Http\Requests;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class CategoryRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array<string, mixed>
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name' => 'required|min:3|max:255',
  28 + //'description' => 'required|min:5',
  29 + 'image' => [
  30 + 'mimes:jpeg,jpg,png',
  31 + 'max:10000'
  32 + ],
  33 + ];
  34 + }
  35 +
  36 + public function messages() {
  37 + return [
  38 + 'required' => 'Поле :attribute обязательно для ввода',
  39 + 'min' => [
  40 + 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
  41 + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
  42 + ],
  43 + 'max' => [
  44 + 'string' => 'Поле «:attribute» должно быть не больше :max символов',
  45 + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
  46 + ],
  47 +
  48 + ];
  49 + }
  50 +
  51 +}
app/Models/Category.php
... ... @@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
8 8 class Category extends Model
9 9 {
10 10 use HasFactory;
  11 +
  12 + protected $fillable = ['name', 'image', 'content', 'parent_id'];
11 13 }
app/Providers/ComposerServiceProvider.php
... ... @@ -0,0 +1,57 @@
  1 +<?php
  2 +
  3 +namespace App\Providers;
  4 +
  5 +use App\Models\Category;
  6 +use Illuminate\Support\Facades\View;
  7 +use Illuminate\Support\ServiceProvider;
  8 +
  9 +class ComposerServiceProvider extends ServiceProvider
  10 +{
  11 + /**
  12 + * Register services.
  13 + *
  14 + * @return void
  15 + */
  16 + public function register()
  17 + {
  18 + $views = [
  19 + 'layout.part.categories', //меню в правой колонке в публичной части
  20 + 'admin.part.categories', //выбор категории поста при редактировании
  21 + 'admin.part.parents', //выбор родителя категории при редактировании
  22 + 'admin.part.all-ctgs', //все категории в административной части
  23 + ];
  24 + View::composer($views,
  25 + function($view) {
  26 + static $items = null;
  27 + if (is_null($items)) {
  28 + $items = Category::all();
  29 + }
  30 + $view->with(['items' => $items]);
  31 + });
  32 + }
  33 +
  34 + /**
  35 + * Bootstrap services.
  36 + *
  37 + * @return void
  38 + */
  39 + public function boot()
  40 + {
  41 + View::composer('layout.part.categories',
  42 + function($view)
  43 + {
  44 + static $items = null;
  45 +
  46 + if (is_null($items)) {
  47 + $items = Category::all();
  48 + $parent = 0;
  49 + $view->with(['items' => $items, 'parent' => $parent]);
  50 + } else {
  51 + $view->with(['items' => $items]);
  52 + }
  53 +
  54 + }
  55 + );
  56 + }
  57 +}
... ... @@ -194,6 +194,7 @@ return [
194 194 // App\Providers\BroadcastServiceProvider::class,
195 195 App\Providers\EventServiceProvider::class,
196 196 App\Providers\RouteServiceProvider::class,
  197 + App\Providers\ComposerServiceProvider::class,
197 198  
198 199 ],
199 200  
resources/views/admin/banners/create.blade.php
... ... @@ -0,0 +1,15 @@
  1 +@extends('layout.admin', ['title' => 'Создание баннера'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Создание баннера
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.banner.store') }}">
  10 + @include('admin.banners.form')
  11 + </form>
  12 +
  13 + </div>
  14 + </div>
  15 +@endsection
resources/views/admin/banners/edit.blade.php
... ... @@ -0,0 +1,14 @@
  1 +@extends('layout.admin', ['title' => 'Редактирование баннера'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Редактирование баннера
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.banner.update', ['banner' => $banner->id]) }}">
  10 + @include('admin.banners.form')
  11 + </form>
  12 + </div>
  13 + </div>
  14 +@endsection
resources/views/admin/banners/form.blade.php
... ... @@ -0,0 +1,37 @@
  1 +@csrf
  2 +
  3 +@isset($banner)
  4 + @method('PUT')
  5 +@endisset
  6 +
  7 +<label class="form__label" for="title">Заголовок баннера
  8 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  9 +</label><br>
  10 +@error('title')
  11 +<div class="alert alert-danger">{{ $message }}</div>
  12 +@enderror
  13 +<input class="form-input " type="text" id="title" name="title" placeholder="Введите заголовок" required value="{{ old('title') ?? $banner->title ?? '' }}"><br><br>
  14 +
  15 +<label class="form__label" for="text">Описание баннера
  16 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  17 +</label><br>
  18 +@error('text')
  19 +<div class="alert alert-danger">{{ $message }}</div>
  20 +@enderror
  21 +<textarea class="form-input " id="text" name="text" placeholder="Введите текст"
  22 + required>{{ old('text') ?? $banner->text ?? '' }}</textarea><br><br>
  23 +
  24 +
  25 +<label class="form__label" for="image">Картинка
  26 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  27 +</label><br>
  28 +<input type="file" class="form-input form-control-file " name="image" id="image" accept="image/png, image/jpeg">
  29 +@isset($banner->image)
  30 + <div class="form-group form-check">
  31 + <img src="<?=asset(Storage::url($banner->image))?>" width="100px"/>
  32 + </div>
  33 +@endisset
  34 +
  35 +<<div class="parts-content-form-bottom modal-auth-bottom">
  36 + <button class="parts-content-form-bottom__button" type="submit">Сохранить</button>
  37 +</div>
resources/views/admin/banners/index.blade.php
1   -@extends('layout.admin', ['title' => 'Профиль пользователя'])
  1 +@extends('layout.admin', ['title' => 'Баннеры'])
2 2  
3 3 @section('content')
4 4 <!-- главный экран -->
5 5 <div class="profile-block-wrapper">
6 6 <div class="profile-block">
  7 + <h2 class="modal-auth__title_">
  8 + Баннеры
  9 + </h2><br>
7 10 <a href="{{ route('admin.banner.create') }}" class="btn banner-container__button" style="margin: 0px;">
8 11 Создать баннер
9 12 </a><br><br>
resources/views/admin/category/create.blade.php
... ... @@ -0,0 +1,15 @@
  1 +@extends('layout.admin', ['title' => 'Создание категории'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Создание категории
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.category.store') }}">
  10 + @include('admin.category.form')
  11 + </form>
  12 +
  13 + </div>
  14 + </div>
  15 +@endsection
resources/views/admin/category/edit.blade.php
... ... @@ -0,0 +1,14 @@
  1 +@extends('layout.admin', ['title' => 'Редактирование категории'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Редактирование категории
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.category.update', ['category' => $category->id]) }}">
  10 + @include('admin.category.form')
  11 + </form>
  12 + </div>
  13 + </div>
  14 +@endsection
resources/views/admin/category/form.blade.php
... ... @@ -0,0 +1,51 @@
  1 +@csrf
  2 +
  3 +@isset($category)
  4 + @method('PUT')
  5 +@endisset
  6 +
  7 +<label class="form__label" for="name">Заголовок категории
  8 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  9 +</label><br>
  10 +@error('name')
  11 +<div class="alert alert-danger">{{ $message }}</div>
  12 +@enderror
  13 +<input class="form-input " type="text" id="name" name="name" placeholder="Введите заголовок" required value="{{ old('name') ?? $category->name ?? '' }}"><br><br>
  14 +
  15 +<label class="form__label" for="content">Описание категории
  16 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  17 +</label><br>
  18 +@error('content')
  19 +<div class="alert alert-danger">{{ $message }}</div>
  20 +@enderror
  21 +<textarea class="form-input " id="content" name="content" placeholder="Введите текст"
  22 + required>{{ old('text') ?? $category->content ?? '' }}</textarea><br><br>
  23 +
  24 +
  25 +<label class="form__label" for="image">Картинка
  26 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  27 +</label><br>
  28 +<input type="file" class="form-input form-control-file " name="image" id="image" accept="image/png, image/jpeg">
  29 +@isset($category->image)
  30 + <div class="form-group form-check">
  31 + <img src="<?=asset(Storage::url($category->image))?>" width="100px"/>
  32 + </div>
  33 +@endisset
  34 +
  35 +<label class="form__label" for="image">Категория-родитель
  36 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  37 +</label><br>
  38 +
  39 +<div class="form-group">
  40 + @php
  41 + $parent_id = old('parent_id') ?? $category->parent_id ?? 0;
  42 + @endphp
  43 + <select name="parent_id" class="form-control" title="Родитель">
  44 + <option value="0">Без родителя</option>
  45 + @include('admin.part.parents', ['level' => -1, 'parent' => 0])
  46 + </select>
  47 +</div>
  48 +
  49 +<<div class="parts-content-form-bottom modal-auth-bottom">
  50 + <button class="parts-content-form-bottom__button" type="submit">Сохранить</button>
  51 +</div>
resources/views/admin/category/index.blade.php
... ... @@ -0,0 +1,64 @@
  1 +@extends('layout.admin', ['title' => 'Категории'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title_">
  7 + Категории
  8 + </h2><br>
  9 + <a href="{{ route('admin.category.create') }}" class="btn banner-container__button" style="margin: 0px;">
  10 + Создать категорию
  11 + </a><br><br>
  12 +
  13 + <table class="table" style="width: 100%">
  14 + <thead>
  15 + <tr>
  16 + <th>ID</th>
  17 + <th>Фото</th>
  18 + <th>Заголовок</th>
  19 + <th>Дата создания</th>
  20 + <th>Действия</th>
  21 + </tr>
  22 + </thead>
  23 + <tbody>
  24 + @if ($categories->count())
  25 + @foreach($categories as $category)
  26 + <tr>
  27 + <td>{{ $category->id }}</td>
  28 + <td><? if (empty($category->image)) {?>Нет фото<?} else {?>
  29 + <!--<img src="/storage/app/public/<?//=$area->foto_main; //=asset(Storage::url($area->foto_main))?>" width="100px"/>-->
  30 + <img src="<?=asset(Storage::url($category->image))?>" width="100px"/>
  31 + <?}?></td>
  32 +
  33 + <td>{{ $category->name }}</td>
  34 + <td>{{ $category->created_at }}</td>
  35 + <td> <form action="{{ route('admin.category.destroy', $category) }}" method="POST">
  36 + <a href="{{ route('admin.category.edit', ['category' => $category->id]) }}">
  37 + Редактировать
  38 + </a> |
  39 + @csrf
  40 + @method('DELETE')
  41 + <input class=" btn-danger" type="submit" value="Удалить">
  42 + </form>
  43 + </td>
  44 + </tr>
  45 + @endforeach
  46 + @else
  47 + <tr>
  48 + <td>-</td>
  49 + <td>-</td>
  50 + <td>-</td>
  51 + <td>-</td>
  52 + <td>-</td>
  53 + </tr>
  54 + @endif
  55 +
  56 + </tbody>
  57 + </table>
  58 +
  59 + {{ $categories->onEachSide(1)->links('catalogs.paginate') }}
  60 +
  61 + </div>
  62 + </div>
  63 + <br><br>
  64 +@endsection
resources/views/admin/news/create.blade.php
... ... @@ -0,0 +1,15 @@
  1 +@extends('layout.admin', ['title' => 'Создание новости'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Создание новости
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.news.store') }}">
  10 + @include('admin.news.form')
  11 + </form>
  12 +
  13 + </div>
  14 + </div>
  15 +@endsection
resources/views/admin/news/edit.blade.php
... ... @@ -0,0 +1,14 @@
  1 +@extends('layout.admin', ['title' => 'Редактирование новости'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Редактирование новости
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.news.update', ['category' => $category->id]) }}">
  10 + @include('admin.news.form')
  11 + </form>
  12 + </div>
  13 + </div>
  14 +@endsection
resources/views/admin/news/form.blade.php
... ... @@ -0,0 +1,37 @@
  1 +@csrf
  2 +
  3 +@isset($news)
  4 + @method('PUT')
  5 +@endisset
  6 +
  7 +<label class="form__label" for="title">Заголовок новости
  8 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  9 +</label><br>
  10 +@error('title')
  11 +<div class="alert alert-danger">{{ $message }}</div>
  12 +@enderror
  13 +<input class="form-input " type="text" id="title" name="title" placeholder="Введите заголовок" required value="{{ old('title') ?? $news->title ?? '' }}"><br><br>
  14 +
  15 +<label class="form__label" for="text">Описание новости
  16 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  17 +</label><br>
  18 +@error('text')
  19 +<div class="alert alert-danger">{{ $message }}</div>
  20 +@enderror
  21 +<textarea class="form-input " id="text" name="text" placeholder="Введите текст"
  22 + required>{{ old('text') ?? $news->text ?? '' }}</textarea><br><br>
  23 +
  24 +
  25 +<label class="form__label" for="image">Картинка
  26 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  27 +</label><br>
  28 +<input type="file" class="form-input form-control-file " name="image" id="image" accept="image/png, image/jpeg">
  29 +@isset($news->image)
  30 + <div class="form-group form-check">
  31 + <img src="<?=asset(Storage::url($news->image))?>" width="100px"/>
  32 + </div>
  33 +@endisset
  34 +
  35 +<<div class="parts-content-form-bottom modal-auth-bottom">
  36 + <button class="parts-content-form-bottom__button" type="submit">Сохранить</button>
  37 +</div>
resources/views/admin/news/index.blade.php
... ... @@ -0,0 +1,64 @@
  1 +@extends('layout.admin', ['title' => 'Новости'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title_">
  7 + Новости
  8 + </h2><br>
  9 + <a href="{{ route('admin.news.create') }}" class="btn banner-container__button" style="margin: 0px;">
  10 + Создать категорию
  11 + </a><br><br>
  12 +
  13 + <table class="table" style="width: 100%">
  14 + <thead>
  15 + <tr>
  16 + <th>ID</th>
  17 + <th>Фото</th>
  18 + <th>Заголовок</th>
  19 + <th>Дата создания</th>
  20 + <th>Действия</th>
  21 + </tr>
  22 + </thead>
  23 + <tbody>
  24 + @if ($news->count())
  25 + @foreach($news as $new)
  26 + <tr>
  27 + <td>{{ $new->id }}</td>
  28 + <td><? if (empty($new->image)) {?>Нет фото<?} else {?>
  29 + <!--<img src="/storage/app/public/<?//=$area->foto_main; //=asset(Storage::url($area->foto_main))?>" width="100px"/>-->
  30 + <img src="<?=asset(Storage::url($new->image))?>" width="100px"/>
  31 + <?}?></td>
  32 +
  33 + <td>{{ $new->title }}</td>
  34 + <td>{{ $new->created_at }}</td>
  35 + <td> <form action="{{ route('admin.news.destroy', $new) }}" method="POST">
  36 + <a href="{{ route('admin.news.edit', ['news' => $new->id]) }}">
  37 + Редактировать
  38 + </a> |
  39 + @csrf
  40 + @method('DELETE')
  41 + <input class=" btn-danger" type="submit" value="Удалить">
  42 + </form>
  43 + </td>
  44 + </tr>
  45 + @endforeach
  46 + @else
  47 + <tr>
  48 + <td>-</td>
  49 + <td>-</td>
  50 + <td>-</td>
  51 + <td>-</td>
  52 + <td>-</td>
  53 + </tr>
  54 + @endif
  55 +
  56 + </tbody>
  57 + </table>
  58 +
  59 + {{ $news->onEachSide(1)->links('catalogs.paginate') }}
  60 +
  61 + </div>
  62 + </div>
  63 + <br><br>
  64 +@endsection
resources/views/admin/part/parents.blade.php
... ... @@ -0,0 +1,10 @@
  1 +@if ($items->where('parent_id', $parent)->count())
  2 + @php $level++ @endphp
  3 + @foreach ($items->where('parent_id', $parent) as $item)
  4 + <option value="{{ $item->id }}" @if ($item->id == $parent_id) selected @endif>
  5 + @if ($level) {!! str_repeat('&nbsp;&nbsp;&nbsp;', $level) !!} @endif
  6 + {{ $item->name }}
  7 + </option>
  8 + @include('admin.part.parents', ['level' => $level, 'parent' => $item->id])
  9 + @endforeach
  10 +@endif
resources/views/admin/projects/create.blade.php
... ... @@ -0,0 +1,15 @@
  1 +@extends('layout.admin', ['title' => 'Создание проекта'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Создание проекта
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.project.store') }}">
  10 + @include('admin.projects.form')
  11 + </form>
  12 +
  13 + </div>
  14 + </div>
  15 +@endsection
resources/views/admin/projects/edit.blade.php
... ... @@ -0,0 +1,14 @@
  1 +@extends('layout.admin', ['title' => 'Редактирование проекта'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title">
  7 + Редактирование проекта
  8 + </h2>
  9 + <form method="post" enctype="multipart/form-data" class="modal-auth-form" action="{{ route('admin.project.update', ['project' => $project->id]) }}">
  10 + @include('admin.projects.form')
  11 + </form>
  12 + </div>
  13 + </div>
  14 +@endsection
resources/views/admin/projects/form.blade.php
... ... @@ -0,0 +1,46 @@
  1 +<?php
  2 +use Illuminate\Support\Facades\Storage;
  3 +?>
  4 +@csrf
  5 +
  6 +@isset($project)
  7 + @method('PUT')
  8 +@endisset
  9 +
  10 +<label class="form__label" for="title">Заголовок
  11 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  12 +</label><br>
  13 +@error('title')
  14 +<div class="alert alert-danger">{{ $message }}</div>
  15 +@enderror
  16 +<input class="form-input " type="text" id="title" name="title" placeholder="Введите заголовок" required value="{{ old('title') ?? $project->title ?? '' }}"><br><br>
  17 +
  18 +<label class="form__label" for="customer">Заказчик
  19 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  20 +</label><br>
  21 +@error('customer')
  22 +<div class="alert alert-danger">{{ $message }}</div>
  23 +@enderror
  24 +<input class="form-input " type="text" id="customer" name="customer" placeholder="Введите заказчика" required value="{{ old('customer') ?? $project->customer ?? '' }}"><br><br>
  25 +
  26 +<label class="form__label" for="date_project">Дата сдачи проекта
  27 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  28 +</label><br>
  29 +@error('date_project')
  30 +<div class="alert alert-danger">{{ $message }}</div>
  31 +@enderror
  32 +<input class="form-input " type="text" id="date_project" name="date_project" placeholder="Введите дату" required value="{{ old('date_project') ?? $project->date_project ?? '' }}"><br><br>
  33 +
  34 +<label class="form__label" for="image">Картинка
  35 + <span class="auth-mail-error auth-mail-error--hidden">Ошибка</span>
  36 +</label><br>
  37 +<input type="file" class="form-input form-control-file " name="image" id="image" accept="image/png, image/jpeg">
  38 +@isset($project->image)
  39 + <div class="form-group form-check">
  40 + <img src="<?=asset(Storage::url($project->image))?>" width="100px"/>
  41 + </div>
  42 +@endisset
  43 +
  44 +<<div class="parts-content-form-bottom modal-auth-bottom">
  45 + <button class="parts-content-form-bottom__button" type="submit">Сохранить</button>
  46 +</div>
resources/views/admin/projects/index.blade.php
... ... @@ -0,0 +1,64 @@
  1 +@extends('layout.admin', ['title' => 'Проекты'])
  2 +
  3 +@section('content')
  4 + <div class="profile-block-wrapper">
  5 + <div class="profile-block">
  6 + <h2 class="modal-auth__title_">
  7 + Проекты
  8 + </h2><br>
  9 + <a href="{{ route('admin.project.create') }}" class="btn banner-container__button" style="margin: 0px;">
  10 + Создать проект
  11 + </a><br><br>
  12 +
  13 + <table class="table" style="width: 100%">
  14 + <thead>
  15 + <tr>
  16 + <th>ID</th>
  17 + <th>Фото</th>
  18 + <th>Заголовок</th>
  19 + <th>Дата создания</th>
  20 + <th>Действия</th>
  21 + </tr>
  22 + </thead>
  23 + <tbody>
  24 + @if ($projects->count())
  25 + @foreach($projects as $project)
  26 + <tr>
  27 + <td>{{ $project->id }}</td>
  28 + <td><? if (empty($project->image)) {?>Нет фото<?} else {?>
  29 + <!--<img src="/storage/app/public/<?//=$area->foto_main; //=asset(Storage::url($area->foto_main))?>" width="100px"/>-->
  30 + <img src="<?=asset(Storage::url($project->image))?>" width="100px"/>
  31 + <?}?></td>
  32 +
  33 + <td>{{ $project->title }}</td>
  34 + <td>{{ $project->created_at }}</td>
  35 + <td> <form action="{{ route('admin.project.destroy', $project) }}" method="POST">
  36 + <a href="{{ route('admin.project.edit', ['project' => $project->id]) }}">
  37 + Редактировать
  38 + </a> |
  39 + @csrf
  40 + @method('DELETE')
  41 + <input class=" btn-danger" type="submit" value="Удалить">
  42 + </form>
  43 + </td>
  44 + </tr>
  45 + @endforeach
  46 + @else
  47 + <tr>
  48 + <td>-</td>
  49 + <td>-</td>
  50 + <td>-</td>
  51 + <td>-</td>
  52 + <td>-</td>
  53 + </tr>
  54 + @endif
  55 +
  56 + </tbody>
  57 + </table>
  58 +
  59 + {{ $projects->onEachSide(1)->links('catalogs.paginate') }}
  60 +
  61 + </div>
  62 + </div>
  63 + <br><br>
  64 +@endsection
resources/views/layout/admin.blade.php
... ... @@ -443,13 +443,13 @@
443 443 Личный кабинет
444 444 </h1>
445 445 <div class="account-content">
446   - <div class="account-left">
  446 + <div class="account-left" style="margin-bottom:35px;">
447 447 <ul class="catalog__tabs account-tabs">
448   - <li class="tab active account-tabs__item js_my_profile" data-tab=".js-tab_1">
  448 + <li class="tab active_ account-tabs__item js_my_profile_" data-tab=".js-tab_1">
449 449 <a href="{{ route('user.index') }}">Мой профиль</a>
450 450 </li>
451 451 <li class="tab account-tabs__item" data-tab=".js-tab_2">
452   - <a href="{{ route('user.index') }}">Категории</a>
  452 + <a href="{{ route('admin.category.index') }}">Категории</a>
453 453 <!--<span>(4)</span>-->
454 454 </li>
455 455 <li class="tab account-tabs__item" data-tab=".js-tab_3">
... ... @@ -457,14 +457,14 @@
457 457 <!--<span>(48)</span>-->
458 458 </li>
459 459 <li class="tab account-tabs__item" data-tab=".js-tab_4">
460   - <a href="{{ route('user.index') }}">Новости</a>
  460 + <a href="{{ route('admin.news.index') }}">Новости</a>
461 461 <!--<span>(5)</span>-->
462 462 </li>
463 463 <li class="tab account-tabs__item" data-tab=".js-tab_5">
464 464 <a href="{{ route('user.index') }}">Товары</a>
465 465 </li>
466 466 <li class="tab account-tabs__item" data-tab=".js-tab_5">
467   - <a href="{{ route('user.index') }}">Проекты</a>
  467 + <a href="{{ route('admin.project.index') }}">Проекты</a>
468 468 </li>
469 469 <li class="tab account-tabs__item" data-tab=".js-tab_5">
470 470 <a href="{{ route('user.index') }}">Компания</a>
... ... @@ -473,7 +473,7 @@
473 473 <a class="account-left__exit" href="{{ route('auth.logout') }}">
474 474 Выйти из аккаунта
475 475 </a>
476   - </div>
  476 + </div><br><br>
477 477 <div class="tabs__content catalog-content-items">
478 478 <!-- содержимое мой профиль -->
479 479 <div class="tabs__item tabs__item-active js-tab_1_">