From 20f53a4dbc3b116b2c1e682af93ed9f40621509f Mon Sep 17 00:00:00 2001 From: YasirDevJS Date: Tue, 19 Nov 2024 01:56:41 +0500 Subject: [PATCH] completed Laravel Blade test --- app/Http/Controllers/HomeController.php | 6 +- app/Providers/AppServiceProvider.php | 5 +- resources/views/alert.blade.php | 7 +- resources/views/authenticated.blade.php | 12 ++- resources/views/include.blade.php | 7 +- resources/views/layout.blade.php | 22 ++--- resources/views/rows.blade.php | 21 +++-- resources/views/table.blade.php | 27 +++--- tests/Feature/ViewsTest.php | 5 +- tests/Feature/dsfsd.php | 107 ++++++++++++++++++++++++ 10 files changed, 172 insertions(+), 47 deletions(-) create mode 100644 tests/Feature/dsfsd.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3ec9546d..8aec84ea 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -11,15 +11,15 @@ 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 public function alert() { - $text = ''; + // $text = ''; - return view('alert', compact('text')); + return view('alert'); } // Task 3. Change the View code to show users, or row "No content" if 0 users diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 38c135bd..9d30f522 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -24,6 +24,9 @@ public function register() */ public function boot() { - // + View::composer('*', function ($view) { + // You can set your global meta title here + $view->with('metaTitle', 'Blade Test'); + }); } } diff --git a/resources/views/alert.blade.php b/resources/views/alert.blade.php index 68bf0b9d..f2e3095e 100644 --- a/resources/views/alert.blade.php +++ b/resources/views/alert.blade.php @@ -1,15 +1,14 @@ -

+

{{ __('Security alert') }}

-
-
+
+
- {!! $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..4d687601 100644 --- a/resources/views/authenticated.blade.php +++ b/resources/views/authenticated.blade.php @@ -1,18 +1,22 @@ -

+

{{ __('Authenticated?') }}

-
-
+
+
{{-- 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]. + @if(!Auth::check()) No, I am not logged in. + @else + Yes, I am logged in as {{ Auth::user()->email }}. + @endif +
diff --git a/resources/views/include.blade.php b/resources/views/include.blade.php index 95d9bd6c..9ceea380 100644 --- a/resources/views/include.blade.php +++ b/resources/views/include.blade.php @@ -1,13 +1,13 @@ -

+

{{ __('Users') }}

-
-
+
+
@@ -20,6 +20,7 @@ @foreach ($users as $user) {{-- Task: include file resources/views/includes/row.blade.php --}} + @include('includes.row', $user) {{-- passing the $user variable to it --}} @endforeach diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index f8ffc5b6..41f3f159 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -1,13 +1,15 @@ - -
-
-
-
- {{-- Task: change the layout from layouts/app.blade.php --}} - {{-- to layouts/main.blade.php --}} - Please change layout. -
+@extends('layouts.main') +@section('content') + +
+
+
+
+ {{-- Task: change the layout from layouts/app.blade.php --}} + {{-- to layouts/main.blade.php --}} + Please change layout.
- +
+@endsection diff --git a/resources/views/rows.blade.php b/resources/views/rows.blade.php index 4762a090..3adaa86b 100644 --- a/resources/views/rows.blade.php +++ b/resources/views/rows.blade.php @@ -1,13 +1,13 @@ -

+

{{ __('Users') }}

-
-
+
+
@@ -19,13 +19,18 @@ - @foreach ($users as $user) + @foreach ($users as $key => $user) {{-- Task: only every second row should have "bg-red-100" --}} - - + + + + + - {{-- Task: only the FIRST row should have email with "font-bold" --}} - + + + + @endforeach diff --git a/resources/views/table.blade.php b/resources/views/table.blade.php index 399bf5c0..379d1b36 100644 --- a/resources/views/table.blade.php +++ b/resources/views/table.blade.php @@ -1,13 +1,13 @@ -

+

{{ __('Users') }}

-
-
+
+
{{-- Task: add row number here: 1, 2, etc. --}}
{{ $key + 1 }} {{ $user->name }}{{ $user->email }}{{ $user->email }}{{ $user->created_at }}
@@ -19,14 +19,19 @@ {{-- Task: add the loop here to show users, or the row "No content" --}} - - - - - - - - + @forelse ( $users as $user ) + + + + + + @empty + + + + @endforelse + +
{{ $user->name }}{{ $user->email }}{{ $user->created_at }}
No content.
{{ $user->name }}{{ $user->email }}{{ $user->created_at }}
No content.
diff --git a/tests/Feature/ViewsTest.php b/tests/Feature/ViewsTest.php index 032b74ce..172b8bc6 100644 --- a/tests/Feature/ViewsTest.php +++ b/tests/Feature/ViewsTest.php @@ -20,7 +20,7 @@ public function test_script_alert_does_not_fire_modal() { $response = $this->get('/alert'); $this->assertStringNotContainsString('\r\n + \r\n + \r\n +
\r\n + \r\n +\r\n + \r\n +
\r\n +
\r\n +

\n + Security alert\n +

\r\n +
\r\n +
\r\n +\r\n + \r\n +
\r\n +
\n +
\n +
\n +
\n + Your task is to change the code of alert.blade.php, to avoid that JavaScript alert.\n +
\n +
\n +
\n +
\r\n +
\r\n +
\r\n + \r\n +\r\n