Skip to content

Commit

Permalink
laravel blade commits
Browse files Browse the repository at this point in the history
  • Loading branch information
adel14524 committed Oct 30, 2024
1 parent 4b534fd commit 5f7670d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 22 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
4 changes: 3 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function register()
*/
public function boot()
{
//
view()->composer('*', function ($view) {
$view->with('metaTitle', 'Blade Test');
});
}
}
2 changes: 1 addition & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// \App\Models\User::factory(10)->create();
\App\Models\User::factory(10)->create();
}
}
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
9 changes: 7 additions & 2 deletions resources/views/authenticated.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
<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
1 change: 1 addition & 0 deletions resources/views/include.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<tr class="bg-red-100">
{{-- Task: include file resources/views/includes/row.blade.php --}}
{{-- passing the $user variable to it --}}
@include('includes.row')
</tr>
@endforeach
</tbody>
Expand Down
10 changes: 7 additions & 3 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<x-app-layout>
@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">
{{-- Task: change the layout from layouts/app.blade.php --}}
{{-- to layouts/main.blade.php --}}
Please change layout.
Please change layouts.
</div>
</div>
</div>
</div>
</x-app-layout>
@endsection


14 changes: 9 additions & 5 deletions resources/views/rows.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
</tr>
</thead>
<tbody>
@foreach ($users as $user)
@forelse ($users as $key => $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>
<tr class="@if($key % 2 == 1) bg-red-100 @endif">
<td>{{ $key + 1}}</td>
<td>{{ $user->name }}</td>
{{-- Task: only the FIRST row should have email with "font-bold" --}}
<td class="font-bold">{{ $user->email }}</td>
<td class="@if ($key % 2 == 0) font-bold @endif">{{ $user->email }}</td>
<td>{{ $user->created_at }}</td>
</tr>
@endforeach
@empty
<tr>
<td colspan="3">No content.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
Expand Down
19 changes: 11 additions & 8 deletions resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
</thead>
{{-- Task: add the loop here to show users, or the row "No content" --}}
<tbody>
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->created_at }}</td>
</tr>
<tr>
<td colspan="3">No content.</td>
</tr>
@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 5f7670d

Please sign in to comment.