show.blade.php
DocumentsController@storeにpostする。
<form method="post" action="{{ action('DocumentsController@store', $article) }}"> {{ csrf_field()}} <p> <input type="text" name="login_id" placeholder="iphone/android" value="{{ old('mobile') }}"> @if($errors->has('mobile')) <span class="error">{{ $errors->first('mobile') }}</span> @endif </p> <p> <input type="text" name="role" placeholder="配信日" value="{{ old('published_at') }}"> @if($errors->has('published_at')) <span class="error">{{ $errors->first('published_at') }}</span> @endif </p> <p> <input type="text" name="name" placeholder="原稿" value="{{ old('body') }}"> @if($errors->has('body')) <span class="error">{{ $errors->first('body') }}</span> @endif </p> <p> <input type="submit" value="登録"> </p> </form>
routing
DocumentsController@storeを/articles/{article}/documentsと設定する。
Route::get('/', 'ArticlesController@index'); Route::get('/articles/create', 'ArticlesController@create'); Route::get('/articles/{id}', 'ArticlesController@show')->where('post','[0-9]+'); Route::post('/articles', 'ArticlesController@store'); Route::get('/articles/{id}/edit', 'ArticlesController@edit'); Route::patch('/articles/{article}', 'ArticlesController@update'); Route::delete('/articles/{article}', 'ArticlesController@destroy'); Route::post('/articles/{article}/documents', 'DocuumentsController@store');
mysqlにも値が入りました。
mysql> select * from documents;
+—-+————+——–+————–+——–+———————+———————+
| id | article_id | mobile | published_at | body | created_at | updated_at |
+—-+————+——–+————–+——–+———————+———————+
| 1 | 10 | iphone | 9/12 | aaaaaa | 2018-09-23 08:46:45 | 2018-09-23 08:46:45 |
+—-+————+——–+————–+——–+———————+———————+
1 row in set (0.00 sec)