반응형
routes/web.php에 작성
//layout
Route::get('/aa', function () { //uri가 /aa 일 때,
$Languages = [
'PHP',
'Java',
'C',
'Python'
];
return view('aa',[ //views/aa를 보여라
'Languages' => $Languages
]);
});
Route::get('/bb', function () { //uri가 /bb 일 때,
$alert = [
'Hello',
'<script>alert("Hello22")</script>'
];
return view('bb',[ //views/bb 보여라
'alert' => $alert
]);
});
Route::get('/cc',[App\Http\Controllers\TestController::class,'index']);
//uri가 /cc 일 때, app/Http/Controllers/TestController의 'index' 클래스를 실행해라
views/menu.blade.php에 작성
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>@yield('title', 'Laravel')</title> {{--@section('title')에 주어진게 없다면 title은'laravel'로 한다--}}
<link rel="stylesheet" href="{{ mix('css/tailwind.css') }}">
</head>
<body>
<div class="bg-red-300 p-2">
<a href="/tasks">
<b>hello</b>
</a>
</div>
<div class="container mx-auto">
<ui>
<li> <a href="/aa">aa</a> </li>
<li> <a href="/bb">bb</a> </li>
<li> <a href="/cc">cc</a> </li>
</ui>
<br>
@yield('content') {{--@section('content')--}}
</div>
</body>
</html>
views/aa.blade.php에 작성
@extends('menu') {{--views/menu.blade.php 사용하겠다--}}
@section('title') {{--yield('title')에 넣자--}}
aa
@endsection
@section('content') {{--yield('content')에 넣자--}}
aaaa welcome
<br><br>
<?php var_dump($Languages); ?>
<ul>
@foreach($Languages as $Lang)
<li> {{ $Lang }}</li>
@endforeach
</ul>
@endsection
views/bb.blade.php에 작성
@extends('menu') {{--views/menu.blade.php 사용하겠다--}}
@section('title') {{--yield('title')에 넣자--}}
bb
@endsection
@section('content') {{--yield('content')에 넣자--}}
bbbb welcome
<br><br>
<?php var_dump($alert); ?>
<ul>
@foreach($alert as $al)
<li> {{ $al }}</li>
@endforeach
</ul>
<ul>
@foreach($alert as $al)
<li><?php echo $al; ?></li>
@endforeach
</ul>
@endsection
views/cc.blade.php에 작성
@extends('menu') {{--views/menu.blade.php 사용하겠다--}}
@section('title') {{--yield('title')에 넣자--}}
cc
@endsection
@section('content') {{--yield('content')에 넣자--}}
cccc welcome <br><br>
<ul>
@foreach($Languages as $Lang)
<li> {{ $Lang }}</li>
@endforeach
</ul>
@endsection
App/Http/controller/TestController에 작성
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestController extends Controller
{
public function index(){
$Languages =[
'PHP',
'Java',
'C',
'Python'
];
return view('cc',[
'Languages' => $Languages
]);
}
}
반응형
'📁Framework > 🎵 Laravel' 카테고리의 다른 글
[Laravel] Serialization of 'Illuminate\\Http\\UploadedFile' is not allowed 에러 (0) | 2023.03.08 |
---|---|
[Laravel] Maximum execution time of 60 seconds exceeded 에러 (0) | 2022.05.24 |
[Laravel] routes (0) | 2021.11.17 |
[Laravel] ui 사용하기 (0) | 2021.11.08 |
[Laravel] 구조 파악하기 (0) | 2021.11.08 |