하는 이유 :
하나의 템플릿(부모)을 다른 템플릿(자식)에서도 작동시키고 싶어서,
예를 들면 css디자인을 다른 페이지에서도 같이 보이게 하고 싶은데, 만약에 일일이 페이지 마다 붙이게 되면 코드도 복잡해지고 일일이 수정해야하는 불편함도 생길 수 있다.
그래서 css파일을 부모파일로 해서 적용시킬 다른 템플릿(자식)파일에게 적용시키는 것이다.
<!--view/layouts(새로만든 폴더)/master.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>라라벨 입문</title>
</head>
<body>
@yield('content')
</body>
</html>
<!--welcome.blade.php-->
@extends('layouts.master')
@section('content')
<p>저는 자식 뷰의 'content' 섹션입니다.</p>
@endsection
<!--web.php-->
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/',function(){
return view('welcome');
});
?>
2. @yield('content') :
부분을 상속받는 자식이 가진 content 라고 이름을 붙인 섹션의 내용을 여기에 출력하겠다는 것이다.
자식뷰를 보면 '<p>저는 자식 뷰의 'content' 섹션입니다.</p> ' 라고 해서 중간에 'content'라고 적힌 부분에 @yield 를 적용시키겠다는 것이다.
만약, style, script 섹션을 작동하려면 새로 마스터 레이아웃(파일이 없다면 만들고, 있다면 덧붙이기) 을 열고
@yield('style') 과 @yield('script')를 붙여야한다.