From 5f7670dcd2294e6188c22e71b3aceae254e5df69 Mon Sep 17 00:00:00 2001 From: adel14524 Date: Wed, 30 Oct 2024 11:47:53 +0800 Subject: [PATCH] laravel blade commits --- app/Http/Controllers/HomeController.php | 2 +- app/Providers/AppServiceProvider.php | 4 +++- database/seeders/DatabaseSeeder.php | 2 +- resources/views/alert.blade.php | 2 +- resources/views/authenticated.blade.php | 9 +++++++-- resources/views/include.blade.php | 1 + resources/views/layout.blade.php | 10 +++++++--- resources/views/rows.blade.php | 14 +++++++++----- resources/views/table.blade.php | 19 +++++++++++-------- 9 files changed, 41 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 3ec9546d..1ea08e52 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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 diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 38c135bd..8e242810 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -24,6 +24,8 @@ public function register() */ public function boot() { - // + view()->composer('*', function ($view) { + $view->with('metaTitle', 'Blade Test'); + }); } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 57b73b54..6f2ee28f 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -13,6 +13,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - // \App\Models\User::factory(10)->create(); + \App\Models\User::factory(10)->create(); } } diff --git a/resources/views/alert.blade.php b/resources/views/alert.blade.php index 68bf0b9d..2980b456 100644 --- a/resources/views/alert.blade.php +++ b/resources/views/alert.blade.php @@ -9,7 +9,7 @@
- {!! $text !!} + {{ $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..d5b3d8fd 100644 --- a/resources/views/authenticated.blade.php +++ b/resources/views/authenticated.blade.php @@ -11,8 +11,13 @@
{{-- 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
diff --git a/resources/views/include.blade.php b/resources/views/include.blade.php index 95d9bd6c..6eef306c 100644 --- a/resources/views/include.blade.php +++ b/resources/views/include.blade.php @@ -21,6 +21,7 @@ {{-- Task: include file resources/views/includes/row.blade.php --}} {{-- passing the $user variable to it --}} + @include('includes.row') @endforeach diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php index f8ffc5b6..11cf1139 100644 --- a/resources/views/layout.blade.php +++ b/resources/views/layout.blade.php @@ -1,13 +1,17 @@ - +@extends('layouts.main') + +@section('content')
{{-- Task: change the layout from layouts/app.blade.php --}} {{-- to layouts/main.blade.php --}} - Please change layout. + Please change layouts.
-
+@endsection + + diff --git a/resources/views/rows.blade.php b/resources/views/rows.blade.php index 4762a090..7ee46fcb 100644 --- a/resources/views/rows.blade.php +++ b/resources/views/rows.blade.php @@ -19,16 +19,20 @@ - @foreach ($users as $user) + @forelse ($users as $key => $user) {{-- Task: only every second row should have "bg-red-100" --}} - - {{-- Task: add row number here: 1, 2, etc. --}} + + {{ $key + 1}} {{ $user->name }} {{-- Task: only the FIRST row should have email with "font-bold" --}} - {{ $user->email }} + {{ $user->email }} {{ $user->created_at }} - @endforeach + @empty + + No content. + + @endforelse diff --git a/resources/views/table.blade.php b/resources/views/table.blade.php index 399bf5c0..8cdbcdb6 100644 --- a/resources/views/table.blade.php +++ b/resources/views/table.blade.php @@ -19,14 +19,17 @@ {{-- Task: add the loop here to show users, or the row "No content" --}} - - {{ $user->name }} - {{ $user->email }} - {{ $user->created_at }} - - - No content. - + @forelse ($users as $user) + + {{ $user->name }} + {{ $user->email }} + {{ $user->created_at }} + + @empty + + No content. + + @endforelse