Передача данных в классы компонентов в Laravel

Можно передавать данные в классы компонентов, используя атрибуты HTML. Давайте для примера сделаем два атрибута:

resources/views/components/layout.blade.php<x-alert type="error" message="text" />

Давайте теперь получим эти данные в классе компонента. Для этого для начала объявим наши атрибуты свойствами класса компонента:

app/View/Components/Alert.php<?php
  class Alert extends Component
  {
    public $type;
    public $message;
  }
?>

Теперь получим данные атрибутов в конструкторе:

app/View/Components/Alert.php<?php
  class Alert extends Component
  {
    public $type;
    public $message;

    public function __construct($type, $message)
    {
      $this->type = $type;
      $this->message = $message;
    }
  }
?>

Теперь можем сделать что-нибудь с полученными данными. Например, передадим их в представление:

app/View/Components/Alert.php<?php
  class Alert extends Component
  {
    public $type;
    public $message;

    public function __construct($type, $message)
    {
      $this->type = $type;
      $this->message = $message;
    }
    
    public function render()
    {
      return view('components.alert', [
        'type' => $this->type,
        'message' => $this->message,
      ]);
    }
  }
?>

Выведем их в представлении:

resources/views/components/alert.blade.php<div class="alert alert-{{ $type }}">
  {{ $message }}
</div>
Задание 1

Передайте в компонент Logo путь к картинке и ее alt.