記事の新規作成

routing

Route::get('/', 'PostsController@index');
// Route::get('/posts/{id}', 'PostsController@show');
Route::get('/posts/{post}', 'PostsController@show')->where('post','[0-9]+');
Route::get('/posts/create', 'PostsController@create');

index.blade.php

@section('container')
<h1>
	<a href="{{ url('/posts/create') }}" class="header-menu">New Post</a>
	Blog Posts
</h1>
<ul>
	{{-- 
	@foreach ($posts as $post)
	<li><a href="">{{ $post->title }}</a></li>
	@endforeach
	--}}

	@forelse ($posts as $post)
	<li><a href="{{ action('PostsController@show', $post) }}">{{ $post->title }}</a></li>
	@empty
	<li>No posts yet</li>
	@endforelse
</ul>
@endsection

@extends('layouts.default')

@section('title', 'New Post')

@section('container')
<h1>
	<a href="{{ url('/') }}" class="header-menu">Back</a>
	New Post</h1>
<form method="post" action="{{ url('/posts') }}">
	{{ csrf_field() }}
	<p>
		<input type="text" name="title" placeholder="enter title">
	</p>
	<p>
		<textarea name="body" placeholder="enter body"></textarea>
	</p>
	<p>
		<input type="submit" value="Add">
	</p>
</form>
@endsection

なんじゃこりゃー 洒落にならん。

getではなく、postにします。

Route::get('/', 'PostsController@index');
// Route::get('/posts/{id}', 'PostsController@show');
Route::get('/posts/{post}', 'PostsController@show')->where('post','[0-9]');
Route::get('/posts/create', 'PostsController@create');
Route::post('/posts', 'PostsController@store');