Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,36 @@

use App\Models\User;

class HomeController extends Controller
{
class HomeController extends Controller {
// Task 1. Change the Controller code to pass the variable to the View
public function users()
{
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()
{
public function alert() {
$text = '<script>alert("I am a security alert, your task is to remove me.");</script>';

return view('alert', compact('text'));
}

// Task 3. Change the View code to show users, or row "No content" if 0 users
public function table()
{
public function table() {
$users = User::all();

return view('table', compact('users'));
}

// Task 3. Change the View code to show users, or row "No content" if 0 users
public function rows()
{
public function rows() {
$users = User::all();

return view('rows', compact('users'));
}

public function include()
{
public function include() {
$users = User::all();

return view('include', compact('users'));
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
6 changes: 5 additions & 1 deletion 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].
@auth
Yes, I am logged in as {{ auth()->user()->email }}.
@endauth
@guest
No, I am not logged in.
@endguest
</div>
</div>
</div>
Expand Down
9 changes: 5 additions & 4 deletions resources/views/include.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
</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>
<tr class="bg-red-100">
{{-- Task: include file resources/views/includes/row.blade.php --}}
{{-- passing the $user variable to it --}}
@include('includes.row', $user)
</tr>
@endforeach
</tbody>
</table>
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')

@section('content')
<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">
Please change layout.
</div>
</div>
</div>
</x-app-layout>
</div>
@endsection
87 changes: 53 additions & 34 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@
@props(['metaTitle' => 'Blade Test'])
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">

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

<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">

<!-- Styles -->
<link rel="stylesheet" href="{{ asset('css/app.css') }}">

<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
</head>
<body class="font-sans antialiased">
<div class="min-h-screen bg-gray-100">
@include('layouts.navigation')

<!-- Page Heading -->
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>

<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
</body>

<head>
<meta charset="utf-8">
<meta
name="viewport"
content="width=device-width, initial-scale=1"
>
<meta
name="csrf-token"
content="{{ csrf_token() }}"
>

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

<!-- Fonts -->
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap"
>

<!-- Styles -->
<link
rel="stylesheet"
href="{{ asset('css/app.css') }}"
>

<!-- Scripts -->
<script
src="{{ asset('js/app.js') }}"
defer
></script>
</head>

<body class="font-sans antialiased">
<div class="min-h-screen bg-gray-100">
@include('layouts.navigation')

<!-- Page Heading -->
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>

<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
</body>

</html>
24 changes: 16 additions & 8 deletions resources/views/rows.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@
</thead>
<tbody>
@foreach ($users as $user)
{{-- Task: only every second row should have "bg-red-100" --}}
<tr class="bg-red-100">
<td>{{-- Task: add row number here: 1, 2, etc. --}}</td>
<td>{{ $user->name }}</td>
{{-- Task: only the FIRST row should have email with "font-bold" --}}
<td class="font-bold">{{ $user->email }}</td>
<td>{{ $user->created_at }}</td>
</tr>
{{-- Task: only every second row should have "bg-red-100" --}}
@if ($loop->even)
<tr class="bg-red-100">
@else
<tr>
@endif
<td>{{ $loop->iteration }}</td>
<td>{{ $user->name }}</td>
{{-- Task: only the FIRST row should have email with "font-bold" --}}
@if ($loop->first)
<td class="font-bold">{{ $user->email }}</td>
@else
<td>{{ $user->email }}</td>
@endif
<td>{{ $user->created_at }}</td>
</tr>
@endforeach
</tbody>
</table>
Expand Down
5 changes: 5 additions & 0 deletions resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
</thead>
{{-- Task: add the loop here to show users, or the row "No content" --}}
<tbody>
@if (count($users))
@foreach ($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->created_at }}</td>
</tr>
@endforeach
@else
<tr>
<td colspan="3">No content.</td>
</tr>
@endif
</tbody>
</table>
</div>
Expand Down