<?php
// routes/web.php
Route::get('/posts/{id}', function ($id) {
$posts = [
1 => [
'title' => 'Intro to Laravel',
'content' => 'This is a short intro to Laravel'
],
2 => [
'title' => 'Intro to PHP',
'content' => 'This is a short intro to PHP'
]
];
return view('posts.show', ['post' => $posts[$id]]);
})->name('posts.show');
// resources/views/posts/show.blade.php
@extends('layouts.app')
@section('title', $post['title'])
@section('content')
<h1>{{ $post['title'] }}</h1>
<p>{{ $post['content'] }}</p>
@endsection
<?php
// routes/web.php
Route::get('/posts/{id}', function ($id) {
$posts = [
1 => [
'title' => 'Intro to Laravel',
'content' => 'This is a short intro to Laravel'
],
2 => [
'title' => 'Intro to PHP',
'content' => 'This is a short intro to PHP'
]
];
// abort_if() 추가
abort_if(!isset($posts[$id]), 404);
return view('posts.show', ['post' => $posts[$id]]);
})->name('posts.show');
부족한 설명 봐주셔서 감사합니다.