Skip to content

Commit 2e3c3e0

Browse files
committed
Completed blade tasks
1 parent 4b534fd commit 2e3c3e0

8 files changed

+31
-21
lines changed

app/Http/Controllers/HomeController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function users()
1111
{
1212
$usersCount = User::count();
1313

14-
return view('users');
14+
return view('users', ['usersCount' => $usersCount]);
1515
}
1616

1717
// Task 2. Change the View code so alert would not show on the screen

app/Providers/AppServiceProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function register()
2424
*/
2525
public function boot()
2626
{
27-
//
27+
// Pass $metaTitle as "Blade Test" to all views
28+
view()->share('metaTitle', 'Blade Test');
2829
}
2930
}

resources/views/alert.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
1010
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
1111
<div class="p-6 bg-white border-b border-gray-200">
12-
{!! $text !!}
12+
{{ $text }}
1313
Your task is to change the code of alert.blade.php, to avoid that JavaScript alert.
1414
</div>
1515
</div>

resources/views/authenticated.blade.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
<div class="p-6 bg-white border-b border-gray-200">
1212
{{-- Task: add a condition to show correct text --}}
1313
{{-- If user is logged in, show their email --}}
14-
Yes, I am logged in as [insert_user_email_here].
14+
@auth
15+
Yes, I am logged in as {{ auth()->user()->email }}.
16+
@else
1517
No, I am not logged in.
18+
@endauth
1619
</div>
1720
</div>
1821
</div>

resources/views/include.blade.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
<tr class="bg-red-100">
2222
{{-- Task: include file resources/views/includes/row.blade.php --}}
2323
{{-- passing the $user variable to it --}}
24+
@include('includes.row', ['user' => $user])
2425
</tr>
25-
@endforeach
26+
@endforeach
2627
</tbody>
2728
</table>
2829
</div>

resources/views/layout.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<x-app-layout>
1+
@extends('layouts.main')
22
<div class="py-12">
33
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
44
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
@@ -10,4 +10,4 @@
1010
</div>
1111
</div>
1212
</div>
13-
</x-app-layout>
13+

resources/views/rows.blade.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
</tr>
2020
</thead>
2121
<tbody>
22-
@foreach ($users as $user)
22+
@foreach ($users as $index => $user)
2323
{{-- Task: only every second row should have "bg-red-100" --}}
24-
<tr class="bg-red-100">
25-
<td>{{-- Task: add row number here: 1, 2, etc. --}}</td>
24+
<tr class="{{ $index % 2 === 1 ? 'bg-red-100' : '' }}">
25+
<td>{{-- Task: add row number here: 1, 2, etc. --}}
26+
{{ $index + 1 }}
27+
</td>
2628
<td>{{ $user->name }}</td>
2729
{{-- Task: only the FIRST row should have email with "font-bold" --}}
28-
<td class="font-bold">{{ $user->email }}</td>
30+
<td class="{{ $index === 0 ? 'font-bold' : '' }}">{{ $user->email }}</td>
2931
<td>{{ $user->created_at }}</td>
3032
</tr>
3133
@endforeach

resources/views/table.blade.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
</tr>
1919
</thead>
2020
{{-- Task: add the loop here to show users, or the row "No content" --}}
21-
<tbody>
22-
<tr>
23-
<td>{{ $user->name }}</td>
24-
<td>{{ $user->email }}</td>
25-
<td>{{ $user->created_at }}</td>
26-
</tr>
27-
<tr>
28-
<td colspan="3">No content.</td>
29-
</tr>
30-
</tbody>
21+
<tbody>
22+
@forelse($users as $user)
23+
<tr>
24+
<td>{{ $user->name }}</td>
25+
<td>{{ $user->email }}</td>
26+
<td>{{ $user->created_at }}</td>
27+
</tr>
28+
@empty
29+
<tr>
30+
<td colspan="3">No content.</td>
31+
</tr>
32+
@endforelse
33+
</tbody>
3134
</table>
3235
</div>
3336
</div>

0 commit comments

Comments
 (0)