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']));
    }
}

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.