skip to Main Content

How to pass an Array from x-slot to layouts in Laravel blade template.
This is my layout file

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!--wrapper-->
<div class="wrapper">

    {{ do something to the Array $arr  }}

    {{ $slot }}

</div>
<!--end wrapper-->
</body>
</html>

below is my view file

<x-layout>
    {{ $arr }} <!-- how to pass it to the layout file -->
    <x-slot:arr> array here </x-slot:arr>

</x-layout>

My question is how to pass the $arr to the layout file

My question is how to pass the $arr to the layout file

2

Answers


  1. Maybe you can try with:

    @slot('arr')
        {{ $arr }}
    @endslot
    
    Login or Signup to reply.
  2. public function boot()
    {
        view()->composer(
            'layout.app', 
            function ($view) {
                $view->with('mayArray', $data);
            }
        );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search