-
Notifications
You must be signed in to change notification settings - Fork 140
#1706 admin panel added #1751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
#1706 admin panel added #1751
Conversation
ddm14159
commented
Sep 27, 2025
- Сделал админку (просмотр юзеров, комментариев, решений)
- Добавил признак is_admin в таблицу юзеров
- Админские роуты открыл для админа + дал ему все права в policy
развернул ветку на https://hexlet-sicp-aakz.onrender.com/ru |
|
||
if (!empty($userId)) { | ||
$query->where('user_id', $userId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
для таких вещей (и ниже) нужно сразу использовать Spatie\QueryBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
поправил тут и в app/Http/Controllers/Admin/SolutionController.php
->where('commentable_id', $commentableId); | ||
} | ||
|
||
$comments = $query->orderBy('created_at', 'desc')->paginate(50); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай сразу добавим scope latest() в модель и его используем, чтоыб вручную orderby не прописывать каждый рза.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
он в билдере есть, взял оттуда
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class AdminMiddleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь лучше всего использовать policy для определения прав доступа. Тогда вся логика авторизации будет в одном месте. Есть еще гейты, но честно скажу, я с ними почти что не работал.
https://laravel.com/docs/12.x/authorization
Для единообразия можно определить одну полиси для всей админки, там метод типа access, и использовать ее. ну и доступ кмк лучше определить внутри контроллера/методов, а не в мидлваре, тогда вся логика будет в одном месте и поток выполнения более явный, чем с мидлварой.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
переделал на гейт. с полиси там как будто не так удобно, мы же не с моделью работаем
|
добавил снова юзера, у нас там база чистится каждый раз при деплоях |
поправил сиды и дев-логин, теперь сразу создается админский юзер |
->appends($request->query()); | ||
|
||
$userId = $request->input('filter.user_id'); | ||
$user = $userId ? User::find($userId) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а что это за юзер?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
использовал для вьюхи, если смотрим по конкретному юзеру. убрал
public function devLogin() | ||
{ | ||
$user = User::first(); | ||
$user = User::where(['is_admin' => true])->first(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно в модель добавить скопу admin() для выбора админов.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавил
<div> | ||
<div> | ||
<a href="{{ route('users.show', $user) }}"> | ||
<strong>{{ $user->name ?: __('admin.not_available') }}</strong> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
мне кажется ситуации когда нет имени не может быть.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
убрал
cd92228
to
61eeecc
Compare
61eeecc
to
19c2158
Compare
<a href="{{ route('exercises.show', $comment->commentable) }}"> | ||
<strong>{{ $comment->getCommentableName() }}</strong> | ||
</a> | ||
@endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут можно еще проще сделать, без ифа.
Может быть есть хелпер, может нет (можно создать) аля getCommentableUrl, который будет внутри себя прятать ссылку и содержать логику по получению урла.
</td> | ||
<td> | ||
<span class="text-break">{{ $user->email }}</span> | ||
@if($user->email_verified_at) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай без ифа, просто выводить как есть.
Админка это та вещь, где проще, тем лучше. Тем более с иконками, если их будет сильно много - будет сильно шумно визуально =)
Т.е. можно тупо тексты выводить, наллы, true/false и прочь - это нормально.
public function __construct() | ||
{ | ||
$this->middleware('can:access-admin'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно создать родительский контроллер Admin\Controller, и в нем определить это правило, тогда при добавлении новых секций не придется конструктор дублировать.
пример из рельс
В принципе мне все ок, тут можно например тестировщиков просить кейсов добавить. И потом мержить @marentsov |