라라벨/laravel7스터디
데이터 바인딩 넘기는 방법
땀모
2020. 3. 28. 09:18
1. web.php
Route::get('/', function () {
return view('welcome',[
'info' => '안녕하세요 저는 인포입니다.'
]);
});
2. welcome.blade.php
<x-sidebar title="My Sidebar" :info="$info"/>
3. Sidebar.php info항목 추가
<?php
namespace App\View\Components;
use Illuminate\View\Component;
class Sidebar extends Component
{
public $title;
public $info;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct($title, $info)
{
$this->title = $title;
$this->info = $info;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('components.sidebar');
}
}
4. sidebar.blade.php {{ $info }} 변수 추가입력
<div>
<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component
</div>
결과