1. Sidebar.php  파일에서 list() 메서드를 추가한다.

public function list()
{
return[
'hi',
'hello',
'apple'
];
}


2. render() 컴포넌트에 list() 메서드를  붙인다. (생략이 가능하다)

public function render()
{
return view('components.sidebar',[
'list' => $this->list()
]);
}


3. sedebar.blade.php  list 루프를 돌려준다.

<div>
<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component<br>

@foreach($list as $item)
<ul>
{{ $item }}
</ul>
@endforeach

</div>


결과


4. Sidebar.php 매개변수 넘기기

public function list($string)
{
return[
'hi',
'hello',
'apple',
$string
];
}


5. sidebar.blade.php $list() 매개변수를 넣어준다.

<div>
<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component<br>

@foreach($list('저는 리스트 매개변수입니다') as $item)
<ul>
{{ $item }}
</ul>
@endforeach

</div>


결과


+ Recent posts