0

The @aware Laravel Blade template directive was introduced in Laravel 8, but I still don't understand what it does differently from the already existing @props directive.

For instance, if I use a Blade template like this:

<x-view-content :page="$page ?? ''" />

and the component used above is defined in views/components/view-content.blade.php like this:

@aware(['page'])

<div>
    {{ $page }}
</div>

I get the page successfully rendered inside the component. However, replacing @aware(['page']) with @props(['page']) produces the same result.

I would like to know what the differences between them are.

Udo E.
  • 2,665
  • 2
  • 21
  • 33
  • 1
    [Accessing Parent Data](https://laravel.com/docs/9.x/blade#accessing-parent-data) explains it – brombeer May 09 '22 at 11:03
  • [link](https://laravel.com/docs/9.x/blade#accessing-parent-data) – Mauricio Mendoza May 09 '22 at 11:12
  • @brombeer, yes, it does explain it, but the benefit of introducing the `@aware` directive isn't clear. Does it then mean I can replace all `@aware` directives with `@props` without breaking my code but I can't do it the other way around (replace all `@props` directives with `@aware` )? – Udo E. May 09 '22 at 11:13
  • 3
    @UdoE. you seem to be missing the point about parent and child components. You use `@aware` when you want to **access a parent's data from a child component**. In the example you provided, there's only one component and yes both `aware` and `props` will work because there're no children components which uses the data from your view-content component. – user3532758 May 09 '22 at 11:37

1 Answers1

0

@aware is for accessing data from a parent component where you have @props. You can find here all relevant information. In your case you don't have child component.

knubbe
  • 1,132
  • 2
  • 12
  • 21