From b464635d0216002498c49056e96b82b9ff625d05 Mon Sep 17 00:00:00 2001 From: Tarek-A85 Date: Tue, 10 Sep 2024 23:35:00 +0300 Subject: [PATCH] My solution --- app/Http/Controllers/HomeController.php | 2 +- app/View/Components/AppLayout.php | 2 +- resources/views/alert.blade.php | 2 +- resources/views/authenticated.blade.php | 6 +++++- resources/views/include.blade.php | 1 + resources/views/layout.blade.php | 4 ++-- resources/views/rows.blade.php | 11 ++++++++--- resources/views/table.blade.php | 3 +++ 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3ec9546d..1ea08e52 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -11,7 +11,7 @@ public function users() { $usersCount = User::count(); - return view('users'); + return view('users', compact('usersCount')); } // Task 2. Change the View code so alert would not show on the screen diff --git a/app/View/Components/AppLayout.php b/app/View/Components/AppLayout.php index b45d3425..7717bd23 100644 --- a/app/View/Components/AppLayout.php +++ b/app/View/Components/AppLayout.php @@ -13,6 +13,6 @@ class AppLayout extends Component */ public function render() { - return view('layouts.app'); + return view('layouts.app', ['metaTitle' => 'Blade Test']); } } diff --git a/resources/views/alert.blade.php b/resources/views/alert.blade.php index 68bf0b9d..8a322451 100644 --- a/resources/views/alert.blade.php +++ b/resources/views/alert.blade.php @@ -9,7 +9,7 @@
- {!! $text !!} + Your task is to change the code of alert.blade.php, to avoid that JavaScript alert.
diff --git a/resources/views/authenticated.blade.php b/resources/views/authenticated.blade.php index e200ae1e..6fb068af 100644 --- a/resources/views/authenticated.blade.php +++ b/resources/views/authenticated.blade.php @@ -11,8 +11,12 @@
{{-- Task: add a condition to show correct text --}} {{-- If user is logged in, show their email --}} - Yes, I am logged in as [insert_user_email_here]. + @auth + Yes, I am logged in as {{auth()->user()->email}} + @endauth + @guest No, I am not logged in. + @endguest
diff --git a/resources/views/include.blade.php b/resources/views/include.blade.php index 95d9bd6c..d01e6858 100644 --- a/resources/views/include.blade.php +++ b/resources/views/include.blade.php @@ -19,6 +19,7 @@ @foreach ($users as $user) + @include('includes.row', [$user]) {{-- Task: include file resources/views/includes/row.blade.php --}} {{-- passing the $user variable to it --}} diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index f8ffc5b6..9352a495 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -1,4 +1,4 @@ - +@extends('layouts.main')
@@ -10,4 +10,4 @@
-
+ diff --git a/resources/views/rows.blade.php b/resources/views/rows.blade.php index 4762a090..beff11d0 100644 --- a/resources/views/rows.blade.php +++ b/resources/views/rows.blade.php @@ -21,11 +21,16 @@ @foreach ($users as $user) {{-- Task: only every second row should have "bg-red-100" --}} - - {{-- Task: add row number here: 1, 2, etc. --}} + + even) class="bg-red-100" @endif> + {{-- Task: add row number here: 1, 2, etc. --}} + {{$loop->iteration}} + {{ $user->name }} {{-- Task: only the FIRST row should have email with "font-bold" --}} - {{ $user->email }} + + first) class="font-bold" @endif>{{ $user->email }} + {{ $user->created_at }} @endforeach diff --git a/resources/views/table.blade.php b/resources/views/table.blade.php index 399bf5c0..79bcd1a0 100644 --- a/resources/views/table.blade.php +++ b/resources/views/table.blade.php @@ -18,16 +18,19 @@ {{-- Task: add the loop here to show users, or the row "No content" --}} + @forelse($users as $user) {{ $user->name }} {{ $user->email }} {{ $user->created_at }} + @empty No content. + @endforelse