How to print variable component in Laravel 7?

Asked

Viewed 103 times

1

I have a $user variable in my Controller. So:

public function index()
    {
        $userBiografia = "Biografia do Usuário";
        return view('user.index', compact('userBiografia'));
    }

I can print it peacefully in the "user.index" View using:

{{ $userBiografia }}

So far ok!

The great PROBLEM is: I cannot use this variable within my components. My component structure is like this:

{{ $userBiografia }} //Aqui estou imprimindo na View, ok, mas não é aqui que quero fazer isso.
<div class="profile-sidebar pd-lg-r-25">
   <div class="row">
      @component('user.components.sidebar_left.index')
      @endcomponent
   </div><!-- row -->
</div><!-- profile-sidebar -->

and within this component I call a new component which is where in fact the variable will be printed.

Anyone who can help I really appreciate it, because I haven’t found anything about it.

Thank you!!!

1 answer

0


You need to pass as parameter of the @Component method.

See if this example can help you.

@component('component.pagination', ['collection' => $students, 'class' => 'student-pagination'])
  • I ended up putting everything in this format: "<x-userSidebarLeftWidgetBiografia />", then created a View, in App, by Artisan himself. There I am doing all the data processing. I liked it because the code on the blade is clean. I don’t know if I could understand kkk but the video was this link

  • Ahhh yes, thank you Barttolo!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.