Posts

Showing posts from December, 2024

"Day5 Laravel Assignments: Laravel Blade Templating Basics"

Image
Day5 Laravel Assignments  Laravel Blade Templating Basics Assignment 1: Conditional Statements with Blade Objective: Understand how to use Blade’s conditional @if, @elseif, and @else directives to display content based on conditions. Task: Create a Blade view that displays a personalized message for users based on their role. The roles can be admin, editor, or guest. If the user is an admin, display:  "Welcome Admin!" If the user is an editor, display:  "Welcome Editor!" If the user is a guest, display:  "Welcome Guest!" Solution: Step 1: Controller  First, create a controller method that passes a user role to the view. // UserController.php public function showDashboard() {      $user = User::find(1);    // Assume we're getting the user from the database      return view('dashboard', compact('user')); } Step 2: Blade View Create the Blade view to display the content based on the user's role. <!-- resources/vi...