Skip to content
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

feat(profile): add user chapters tree #40

Merged
merged 4 commits into from Sep 14, 2019

Conversation

grozwalker
Copy link
Contributor

На странице профиля добавил вывод всех глав, если глава прочитана пользователем, то чекбокс нажат

@grozwalker grozwalker force-pushed the profile-chapters branch 2 times, most recently from 38184df to 17fe733 Compare September 8, 2019 21:10

public function getIsReadAttribute()
{
return $this->user->where('id', Auth::user()->id)->count() > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вспоминаем MVC и отношение понятие аутентификации по отношению к модели.

use App\User;

class UserController extends Controller
{
public function show(string $name)
{
$user = User::where('name', $name)->firstOrFail();

$allChapters = Chapter::with('user')->get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Такие штуки должны доставаться через связи

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

так а это не доставание, а просто загрузка данных для жадной загрузки

https://laravel.com/docs/6.0/eloquent-relationships#eager-loading

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А ок, но возникает вопрос, откуда у chapter может быть понятие "пользователь"? Главы сами по себе не привязаны к пользователям напрямую.

@@ -0,0 +1,3 @@
.chapters-tree {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кастомных стилей не надо, в бутстрапе все это есть

use App\User;
use Tests\TestCase;

class ChapterTest extends TestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот смотри, куча кода ради одного примитивного метода. Правда метод все равно написан неправильно.

@grozwalker grozwalker merged commit c0c9bf2 into Hexlet:master Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants