Commit d65c792256657c6d4e7dd352539d28a9fcdf608e
1 parent
f615f47db0
Exists in
master
Проблема пагинации на странице категория и система авторизации на сайте
Showing 13 changed files with 378 additions and 4 deletions Side-by-side Diff
- .htaccess
- app/Http/Controllers/AdminController.php
- app/Http/Controllers/LoginController.php
- app/Http/Controllers/MainController.php
- app/Http/Controllers/RegisterController.php
- resources/views/admin/index.blade.php
- resources/views/auth/login-copy.blade.php
- resources/views/auth/login.blade.php
- resources/views/auth/register-copy.blade.php
- resources/views/auth/register.blade.php
- resources/views/category_catalog.blade.php
- resources/views/layout/site.blade.php
- routes/web.php
.htaccess
app/Http/Controllers/AdminController.php
app/Http/Controllers/LoginController.php
... | ... | @@ -0,0 +1,52 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Http\Controllers; | |
4 | + | |
5 | +use Illuminate\Http\Request; | |
6 | +use Illuminate\Support\Facades\Auth; | |
7 | + | |
8 | +class LoginController extends Controller | |
9 | +{ | |
10 | + public function __construct() { | |
11 | + //$this->middleware('guest')->except('logout'); | |
12 | + } | |
13 | + | |
14 | + //Форма входа | |
15 | + public function login() { | |
16 | + return view('auth.login'); | |
17 | + } | |
18 | + | |
19 | + // Аутентификация | |
20 | + public function autenticate(Request $request) { | |
21 | + $request->validate([ | |
22 | + 'email' => 'required|string|email', | |
23 | + 'password' => 'required|string', | |
24 | + ]); | |
25 | + | |
26 | + $credentials = $request->only('email', 'password'); | |
27 | + | |
28 | + if (Auth::attempt($credentials, $request->has('remember'))) { | |
29 | + if (is_null(Auth::user()->email_verified_at)){ | |
30 | + Auth::logout(); | |
31 | + return redirect() | |
32 | + ->route('auth.vefiry-message') | |
33 | + ->withErrors('Адрес почты не подтвержден'); | |
34 | + } | |
35 | + | |
36 | + return redirect() | |
37 | + ->route('user.index') | |
38 | + ->with('success', 'Вы вошли в личный кабинет.'); | |
39 | + } | |
40 | + | |
41 | + return redirect() | |
42 | + ->route('auth.login') | |
43 | + ->withErrors('Неверный логин или пароль!'); | |
44 | + } | |
45 | + | |
46 | + // Выход | |
47 | + public function logout() { | |
48 | + Auth::logout(); | |
49 | + return redirect()->route('index') | |
50 | + ->with('success', 'Вы вышли из личного кабинета'); | |
51 | + } | |
52 | +} |
app/Http/Controllers/MainController.php
... | ... | @@ -190,7 +190,7 @@ class MainController extends Controller |
190 | 190 | /* |
191 | 191 | * Категории каталога Аренда/Продажа/Бизнес |
192 | 192 | */ |
193 | - public function Category($cat) { | |
193 | + public function Category($cat, Request $request) { | |
194 | 194 | switch ($cat) { |
195 | 195 | case 'arenda': |
196 | 196 | $title = "Аренда торговых помещениий"; |
... | ... | @@ -211,7 +211,8 @@ class MainController extends Controller |
211 | 211 | } |
212 | 212 | |
213 | 213 | $houses = House::with('areas')-> |
214 | - where('format_house', '=', $format_house)->get(); | |
214 | + where('format_house', '=', $format_house)->paginate(4)->appends(request()->query()); | |
215 | + //->appends(request()->query()); | |
215 | 216 | |
216 | 217 | return view('category_catalog', compact('title', 'houses')); |
217 | 218 | } |
app/Http/Controllers/RegisterController.php
... | ... | @@ -0,0 +1,39 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Http\Controllers; | |
4 | + | |
5 | +use App\Models\User; | |
6 | +use Illuminate\Http\Request; | |
7 | +use Illuminate\Support\Facades\Hash; | |
8 | + | |
9 | +// Контроллер регистрации пользователя | |
10 | +class RegisterController extends Controller | |
11 | +{ | |
12 | + public function __construct() { | |
13 | + //$this->middleware('guest'); | |
14 | + } | |
15 | + | |
16 | + // Форма регистрации | |
17 | + public function register() { | |
18 | + return view('auth.register'); | |
19 | + } | |
20 | + | |
21 | + // Создание пользователя | |
22 | + public function create(Request $request) { | |
23 | + $request->validate([ | |
24 | + 'name' => 'required|string|max:255', | |
25 | + 'email' => 'required|string|email|max:255|unique:users', | |
26 | + 'password' => 'required|string|min:8|confirmed', | |
27 | + ]); | |
28 | + | |
29 | + User::create([ | |
30 | + 'name' => $request->name, | |
31 | + 'email' => $request->email, | |
32 | + 'password' => Hash::make($request->password), | |
33 | + ]); | |
34 | + | |
35 | + return redirect() | |
36 | + ->route('auth.login') | |
37 | + ->with('success', 'Вы успешно зарегистрировались'); | |
38 | + } | |
39 | +} |
resources/views/admin/index.blade.php
resources/views/auth/login-copy.blade.php
... | ... | @@ -0,0 +1,45 @@ |
1 | +@extends('layout.site', ['title' => 'Вход в личный кабинет']) | |
2 | + | |
3 | +@section('content') | |
4 | +<section class="favorites"> | |
5 | + <div class="favorites-top"> | |
6 | + <div class="container"> | |
7 | + | |
8 | + <div class="footer-top"> | |
9 | + <div class="container"> | |
10 | + <div class="footer-feedback"> | |
11 | + <div class="footer-feedback__cnt"> | |
12 | + <h2 class="footer-feedback__title title">Вход в личный кабинет</h2> | |
13 | + <p class="footer-feedback__descr">Настройте свой сайт по потребностям</p> | |
14 | + </div> | |
15 | + <form class="footer-feedback__form" method="post" action="{{ route('auth.auth') }}"> | |
16 | + @csrf | |
17 | + <div class="footer-feedback__row"> | |
18 | + <div class="footer-feedback__col"> | |
19 | + <label class="footer-feedback__field field"> | |
20 | + <input type="email" class="form-control" name="email" placeholder="Адрес почты" | |
21 | + required maxlength="255" value="{{ old('email') ?? '' }}"> | |
22 | + </label> | |
23 | + <label class="footer-feedback__field field"> | |
24 | + <input type="text" class="form-control" name="password" placeholder="Ваш пароль" | |
25 | + required maxlength="255" value=""> | |
26 | + </label> | |
27 | + </div> | |
28 | + <div class="footer-feedback__col"> | |
29 | + | |
30 | + </div> | |
31 | + </div> | |
32 | + <div class="footer-feedback__control"> | |
33 | + <!--<button class="footer-feedback__btn btn btn--main js_form_btn">Отправить</button>--> | |
34 | + | |
35 | + <button type="submit" class="btn footer-feedback__btn">Войти</button> | |
36 | + </div> | |
37 | + </form> | |
38 | + </div> | |
39 | + </div> | |
40 | + </div> | |
41 | + | |
42 | + </div> | |
43 | + </div> | |
44 | +</section> | |
45 | +@endsection |
resources/views/auth/login.blade.php
... | ... | @@ -0,0 +1,45 @@ |
1 | +@extends('layout.site', ['title' => 'Вход в личный кабинет']) | |
2 | + | |
3 | +@section('content') | |
4 | + <section class="favorites"> | |
5 | + <div class="favorites-top"> | |
6 | + <div class="container"> | |
7 | + | |
8 | + <div class="footer-top"> | |
9 | + <div class="container"> | |
10 | + <div class="footer-feedback"> | |
11 | + <div class="footer-feedback__cnt"> | |
12 | + <h2 class="footer-feedback__title title">Вход в личный кабинет</h2> | |
13 | + <p class="footer-feedback__descr">Настройте свой сайт по потребностям</p> | |
14 | + </div> | |
15 | + <form class="footer-feedback__form" method="post" action="{{ route('auth.auth') }}"> | |
16 | + @csrf | |
17 | + <div class="footer-feedback__row"> | |
18 | + <div class="footer-feedback__col"> | |
19 | + <label class="footer-feedback__field field"> | |
20 | + <input type="email" class="form-control" name="email" placeholder="Адрес почты" | |
21 | + required maxlength="255" value="{{ old('email') ?? '' }}"> | |
22 | + </label> | |
23 | + <label class="footer-feedback__field field"> | |
24 | + <input type="text" class="form-control" name="password" placeholder="Ваш пароль" | |
25 | + required maxlength="255" value=""> | |
26 | + </label> | |
27 | + </div> | |
28 | + <div class="footer-feedback__col"> | |
29 | + | |
30 | + </div> | |
31 | + </div> | |
32 | + <div class="footer-feedback__control"> | |
33 | + <!--<button class="footer-feedback__btn btn btn--main js_form_btn">Отправить</button>--> | |
34 | + | |
35 | + <button type="submit" class="btn footer-feedback__btn">Войти</button> | |
36 | + </div> | |
37 | + </form> | |
38 | + </div> | |
39 | + </div> | |
40 | + </div> | |
41 | + | |
42 | + </div> | |
43 | + </div> | |
44 | + </section> | |
45 | +@endsection |
resources/views/auth/register-copy.blade.php
... | ... | @@ -0,0 +1,52 @@ |
1 | +@extends('layout.site', ['title' => 'Регистрация']) | |
2 | + | |
3 | +@section('content') | |
4 | +<section class="favorites"> | |
5 | + <div class="favorites-top"> | |
6 | + <div class="container"> | |
7 | + | |
8 | + <div class="footer-top"> | |
9 | + <div class="container"> | |
10 | + <div class="footer-feedback"> | |
11 | + <div class="footer-feedback__cnt"> | |
12 | + <h2 class="footer-feedback__title title">Регистрация</h2> | |
13 | + <p class="footer-feedback__descr">Зарегистрируйте своего пользователя в системе</p> | |
14 | + </div> | |
15 | + <form class="footer-feedback__form" method="post" action="{{ route('auth.register') }}"> | |
16 | + @csrf | |
17 | + <div class="footer-feedback__row"> | |
18 | + <div class="footer-feedback__col"> | |
19 | + <label class="footer-feedback__field field"> | |
20 | + <input type="text" class="form-control" name="name" placeholder="Имя, Фамилия" | |
21 | + required maxlength="255" value="{{ old('name') ?? '' }}"> | |
22 | + </label> | |
23 | + <label class="footer-feedback__field field"> | |
24 | + <input type="email" class="form-control" name="email" placeholder="Адрес почты" | |
25 | + required maxlength="255" value="{{ old('email') ?? '' }}"> | |
26 | + </label> | |
27 | + | |
28 | + <label class="footer-feedback__field field"> | |
29 | + <input type="text" class="form-control" name="password" placeholder="Придумайте пароль" | |
30 | + required maxlength="255" value=""> | |
31 | + </label> | |
32 | + <label class="footer-feedback__field field"> | |
33 | + <input type="text" class="form-control" name="password_confirmation" | |
34 | + placeholder="Пароль еще раз" required maxlength="255" value=""> | |
35 | + </label> | |
36 | + | |
37 | + </div> | |
38 | + <div class="footer-feedback__col"> | |
39 | + </div> | |
40 | + </div> | |
41 | + <div class="footer-feedback__control"> | |
42 | + <!--<button class="footer-feedback__btn btn btn--main js_form_btn">Отправить</button>--> | |
43 | + <button type="submit" class="btn footer-feedback__btn">Регистрация</button> | |
44 | + </div> | |
45 | + </form> | |
46 | + </div> | |
47 | + </div> | |
48 | + </div> | |
49 | + </div> | |
50 | + </div> | |
51 | +</section> | |
52 | +@endsection |
resources/views/auth/register.blade.php
... | ... | @@ -0,0 +1,52 @@ |
1 | +@extends('layout.site', ['title' => 'Регистрация']) | |
2 | + | |
3 | +@section('content') | |
4 | + <section class="favorites"> | |
5 | + <div class="favorites-top"> | |
6 | + <div class="container"> | |
7 | + | |
8 | + <div class="footer-top"> | |
9 | + <div class="container"> | |
10 | + <div class="footer-feedback"> | |
11 | + <div class="footer-feedback__cnt"> | |
12 | + <h2 class="footer-feedback__title title">Регистрация</h2> | |
13 | + <p class="footer-feedback__descr">Зарегистрируйте своего пользователя в системе</p> | |
14 | + </div> | |
15 | + <form class="footer-feedback__form" method="post" action="{{ route('auth.register') }}"> | |
16 | + @csrf | |
17 | + <div class="footer-feedback__row"> | |
18 | + <div class="footer-feedback__col"> | |
19 | + <label class="footer-feedback__field field"> | |
20 | + <input type="text" class="form-control" name="name" placeholder="Имя, Фамилия" | |
21 | + required maxlength="255" value="{{ old('name') ?? '' }}"> | |
22 | + </label> | |
23 | + <label class="footer-feedback__field field"> | |
24 | + <input type="email" class="form-control" name="email" placeholder="Адрес почты" | |
25 | + required maxlength="255" value="{{ old('email') ?? '' }}"> | |
26 | + </label> | |
27 | + | |
28 | + <label class="footer-feedback__field field"> | |
29 | + <input type="text" class="form-control" name="password" placeholder="Придумайте пароль" | |
30 | + required maxlength="255" value=""> | |
31 | + </label> | |
32 | + <label class="footer-feedback__field field"> | |
33 | + <input type="text" class="form-control" name="password_confirmation" | |
34 | + placeholder="Пароль еще раз" required maxlength="255" value=""> | |
35 | + </label> | |
36 | + | |
37 | + </div> | |
38 | + <div class="footer-feedback__col"> | |
39 | + </div> | |
40 | + </div> | |
41 | + <div class="footer-feedback__control"> | |
42 | + <!--<button class="footer-feedback__btn btn btn--main js_form_btn">Отправить</button>--> | |
43 | + <button type="submit" class="btn footer-feedback__btn">Регистрация</button> | |
44 | + </div> | |
45 | + </form> | |
46 | + </div> | |
47 | + </div> | |
48 | + </div> | |
49 | + </div> | |
50 | + </div> | |
51 | + </section> | |
52 | +@endsection |
resources/views/category_catalog.blade.php
... | ... | @@ -569,7 +569,10 @@ |
569 | 569 | </div>--> |
570 | 570 | </div> |
571 | 571 | <div class="pagination"> |
572 | - <div class="pagination__inner"><a class="pagination__btn pagination__btn-prev disabled" href="#"> | |
572 | + <?=$houses->withQueryString()->links('catalogs.paginate'); ?> | |
573 | + | |
574 | + | |
575 | + <!--<div class="pagination__inner"><a class="pagination__btn pagination__btn-prev disabled" href="#"> | |
573 | 576 | <svg width="10" height="17"> |
574 | 577 | <use xlink:href="images/sprite.svg#slider-arrow"></use> |
575 | 578 | </svg></a> |
... | ... | @@ -583,7 +586,8 @@ |
583 | 586 | <svg width="10" height="17"> |
584 | 587 | <use xlink:href="images/sprite.svg#slider-arrow"></use> |
585 | 588 | </svg></a> |
586 | - </div> | |
589 | + </div>--> | |
590 | + | |
587 | 591 | </div> |
588 | 592 | </div> |
589 | 593 | </section> |
resources/views/layout/site.blade.php
... | ... | @@ -79,6 +79,28 @@ |
79 | 79 | </div> |
80 | 80 | </header> |
81 | 81 | <main> |
82 | + @if ($message = Session::get('success')) | |
83 | + <div class="alert alert-success alert-dismissible mt-0" role="alert"> | |
84 | + <button type="button" class="close" data-dismiss="alert" aria-label="Закрыть"> | |
85 | + <span aria-hidden="true">×</span> | |
86 | + </button> | |
87 | + {{ $message }} | |
88 | + </div> | |
89 | + @endif | |
90 | + | |
91 | + @if ($errors->any()) | |
92 | + <div class="alert alert-danger alert-dismissible mt-4" role="alert"> | |
93 | + <button type="button" class="close" data-dismiss="alert" aria-label="Закрыть"> | |
94 | + <span aria-hidden="true">×</span> | |
95 | + </button> | |
96 | + <ul class="mb-0"> | |
97 | + @foreach ($errors->all() as $error) | |
98 | + <li>{{ $error }}</li> | |
99 | + @endforeach | |
100 | + </ul> | |
101 | + </div> | |
102 | + @endif | |
103 | + | |
82 | 104 | <!-- Фильтр --> |
83 | 105 | @yield('filter') |
84 | 106 |
routes/web.php
1 | 1 | <?php |
2 | 2 | |
3 | +use Illuminate\Support\Facades\Auth; | |
3 | 4 | use Illuminate\Support\Facades\Route; |
4 | 5 | use App\Http\Controllers\MainController; |
6 | +use App\Http\Controllers\RegisterController; | |
7 | +use App\Http\Controllers\LoginController; | |
8 | +use App\Http\Controllers\AdminController; | |
5 | 9 | /* |
6 | 10 | |-------------------------------------------------------------------------- |
7 | 11 | | Web Routes |
... | ... | @@ -53,3 +57,36 @@ Route::get('catalog_ajax_filter', [MainController::class, 'catalog_ajax_filter'] |
53 | 57 | |
54 | 58 | //Категория |
55 | 59 | Route::get('category/{cat}', [MainController::class, 'Category'])->name('category'); |
60 | + | |
61 | + | |
62 | +Route::group([ | |
63 | + 'as' => 'auth.', // имя маршрута, например auth.index | |
64 | + 'prefix' => 'auth', // префикс маршрута, например auth/index | |
65 | +], function () { | |
66 | +// Форма регистрации | |
67 | + Route::get('register', [RegisterController::class, 'register'])->name('register'); | |
68 | + | |
69 | +// Создание пользователя | |
70 | + Route::post('register', [RegisterController::class, 'create'])->name('create'); | |
71 | +//Форма входа | |
72 | + Route::get('login', [LoginController::class, 'login'])->name('login'); | |
73 | + | |
74 | +// аутентификация | |
75 | + Route::post('login', [LoginController::class, 'autenticate'])->name('auth'); | |
76 | + | |
77 | +// выход | |
78 | + Route::get('logout', [LoginController::class, 'logout'])->name('logout'); | |
79 | +}); | |
80 | + | |
81 | +/* | |
82 | + * Личный кабинет пользователя | |
83 | + */ | |
84 | +Route::group([ | |
85 | + 'as' => 'user.', // имя маршрута, например user.index | |
86 | + 'prefix' => 'user', // префикс маршрута, например user/index | |
87 | + //'namespace' => 'User', // пространство имен контроллеров | |
88 | + 'middleware' => ['auth'] // один или несколько посредников | |
89 | +], function () { | |
90 | + // главная страница | |
91 | + Route::get('index', [AdminController::class, 'index'])->name('index'); | |
92 | +}); |