0

I can not see my variable in component

Controller

class DigitalContentController extends Controller
{
    public function productsList(){
        $contents = DigitalContent::all();
        return view('pages.digitalContents', compact(['contents']));
    }
}

digitalContents

@extends('layouts.base')

@section('body')

<x-content-card></x-content-card>

@endsection

Component

@foreach ( $contents ?? [] as $item )
    {{ $item->name }}
@endforeach

Even when I echo variable before return view I can see the variable.

class DigitalContentController extends Controller
{
    public function productsList(){
        $contents = DigitalContent::all();
        echo $contents
        return view('pages.digitalContents', compact(['contents']));
    }
}
CC7052
  • 563
  • 5
  • 16

1 Answers1

1

Because you've to parse the variable to the component. So it should be:

<x-content-card :contents="$contents"></x-content-card>

Don't forget to add contents to your component class

Kevin
  • 1,068
  • 5
  • 14
  • 16