Skip to content

Commit

Permalink
Finish exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
TrisCC committed Oct 28, 2024
1 parent 4b534fd commit 18ad891
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 41 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resources/views/alert.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
{!! $text !!}
{{ $text }}
Your task is to change the code of alert.blade.php, to avoid that JavaScript alert.
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions resources/views/authenticated.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
<div class="p-6 bg-white border-b border-gray-200">
{{-- 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].
No, I am not logged in.
@auth
Yes, I am logged in as {{ auth()->user()->email }}.
@endauth
@guest
No, I am not logged in.
@endguest
</div>
</div>
</div>
Expand Down
21 changes: 11 additions & 10 deletions resources/views/include.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
<div class="p-6 bg-white border-b border-gray-200">
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr class="bg-red-100">
{{-- Task: include file resources/views/includes/row.blade.php --}}
{{-- passing the $user variable to it --}}
</tr>
@endforeach
@foreach ($users as $user)
<tr class="bg-red-100">
{{-- Task: include file resources/views/includes/row.blade.php --}}
{{-- passing the $user variable to it --}}
{{ view('includes.row', ['user'=>$user])}}
</tr>
@endforeach
</tbody>
</table>
</div>
Expand Down
20 changes: 10 additions & 10 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<x-app-layout>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
{{-- Task: change the layout from layouts/app.blade.php --}}
{{-- to layouts/main.blade.php --}}
Please change layout.
</div>
@extends('layouts.main')
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
Task: change the layout from layouts/app.blade.php
to layouts/main.blade.php
Please change layout.
</div>
</div>
</div>
</x-app-layout>
</div>

2 changes: 1 addition & 1 deletion resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="csrf-token" content="{{ csrf_token() }}">

{{-- Task: edit one file to pass $metaTitle as "Blade Test" to all views --}}
<title>{{ $metaTitle ?? 'Laravel' }}</title>
<title>{{ $metaTitle ?? 'Blade Test' }}</title>

<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">
Expand Down
30 changes: 19 additions & 11 deletions resources/views/rows.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@
<div class="p-6 bg-white border-b border-gray-200">
<table>
<thead>
<tr>
<th>Row Number</th>
<th>Name</th>
<th>Email</th>
<th>Registered at</th>
</tr>
<tr>
<th>Row Number</th>
<th>Name</th>
<th>Email</th>
<th>Registered at</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
{{-- Task: only every second row should have "bg-red-100" --}}
@foreach ($users as $index=>$user)
{{-- Task: only every second row should have "bg-red-100" --}}
@if($index % 2 == 0)
<tr class="bg-red-100">
<td>{{-- Task: add row number here: 1, 2, etc. --}}</td>
@else
<tr>
@endif
<td>{{-- Task: add row number here: 1, 2, etc. --}} {{$index}}</td>
<td>{{ $user->name }}</td>
{{-- Task: only the FIRST row should have email with "font-bold" --}}
<td class="font-bold">{{ $user->email }}</td>
@if($index == 0)
<td class="font-bold">{{ $user->email }}</td>
@else
<td>{{ $user->email }}</td>
@endif
<td>{{ $user->created_at }}</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
</div>
Expand Down
14 changes: 9 additions & 5 deletions resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
<div class="p-6 bg-white border-b border-gray-200">
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Registered at</th>
</tr>
<tr>
<th>Name</th>
<th>Email</th>
<th>Registered at</th>
</tr>
</thead>
{{-- Task: add the loop here to show users, or the row "No content" --}}

<tbody>
@forelse($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->created_at }}</td>
</tr>
@empty
<tr>
<td colspan="3">No content.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
Expand Down

0 comments on commit 18ad891

Please sign in to comment.