初めまして。
Laravel 5.4でDB連携を試しているのですが、SELECTとDELETEは出来るのですがINSERTとUPDATEができないので、できるようにしたいです。
DBはMySQLです。
エラーは以下の通りです。
ReflectionException in RouteSignatureParameters.php line 25:
Class App\Http\Controllers\ArticleRequest does not exist
この階層にArticleRequestは存在しませんが、
App\Http\Request\の中にあるArticleRequestを上記の階層に移してもエラーは出ました。
ArticleController.phpのソースコードは以下の通りです。
php
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Requests; 6use App\Article; 7 8class ArticleController extends Controller 9{ 10 /** 11 * Display a listing of the resource. 12 * 13 * @return \Illuminate\Http\Response 14 */ 15 public function index() 16 { 17 //一覧表示 18 $data = Article::latest('created_at')->paginate(10); 19 return view('article.index')->with('message','ユーザーリスト')->with('data',$data); 20 } 21 22 /** 23 * Show the form for creating a new resource. 24 * 25 * @return \Illuminate\Http\Response 26 */ 27 public function create() 28 { 29 //新規作成 30 return view('article.create')->with('message','登録するユーザーを入力してください。'); 31 } 32 33 /** 34 * Store a newly created resource in storage. 35 * 36 * @param \Illuminate\Http\Request $request 37 * @return \Illuminate\Http\Response 38 */ 39 public function store(ArticleRequest $request) 40 { 41 //新規保存 42 $article = new Article(); 43 $article->name = $request->name; 44 $article->age = $request->age; 45 $article->save(); 46 47 // View表示 48 $res = $request->input('name').'さんを追加しました。'; 49 $data = Article::latest('created_at')->paginate(10); 50 return redirect('/article/')->with('message',$res)->with('data',$data)->with('status','新規保存の処理完了!'); 51 } 52 53 /** 54 * Display the specified resource. 55 * 56 * @param int $id 57 * @return \Illuminate\Http\Response 58 */ 59 public function show($id) 60 { 61 //詳細表示 62 $user = Article::findOrFail($id); 63 return view('article.show')->with('user', $user); 64 } 65 66 /** 67 * Show the form for editing the specified resource. 68 * 69 * @param int $id 70 * @return \Illuminate\Http\Response 71 */ 72 public function edit($id) 73 { 74 //編集 75 $data = Article::findOrFail($id); 76 return view('article.edit')->with('message','編集フォーム')->with('data',$data); 77 } 78 79 /** 80 * Update the specified resource in storage. 81 * 82 * @param \Illuminate\Http\Request $request 83 * @param int $id 84 * @return \Illuminate\Http\Response 85 */ 86 public function update(ArticleRequest $request, $id) 87 { 88 //更新 89 $article = Article::findOrFail($id); 90 $article->name = $request->name; 91 $article->age = $request->age; 92 $article->save(); 93 94 // View表示 95 $res = $request->input('name')."さんを更新しました。"; 96 $data = Article::latest('created_at')->paginate(10); 97 return redirect('/article/')->with('message',$res)->with('data',$data)->with('status','更新処理完了!'); 98 } 99 100 /** 101 * Remove the specified resource from storage. 102 * 103 * @param int $id 104 * @return \Illuminate\Http\Response 105 */ 106 public function destroy($id) 107 { 108 //削除 109 $article = Article::findOrFail($id); 110 $article->delete(); 111 112 // 削除処理 113 $data = Article::latest('created_at')->get(); 114 return redirect('/article/')->with('status', '削除処理完了!')->with('data',$data); 115 } 116} 117
また、web.phpのソースコードは以下の通りです。
php
1Route::resource('article','ArticleController');
原因を教えていただきたいです。
よろしくお願いします。
新規作成のviewです。
php
1@extends('layouts.default') 2@section('title', '新規作成') 3@section('content') 4 5@if (session('status')) 6<div class="alert alert-success" role="alert" onclick="this.classList.add('hidden')">{{ session('status') }}</div> 7@endif 8 9<p>{{$message}}</p> 10<form class="form-horizontal" role="form" method="post" action="{{url('/article')}}"> 11<input type="hidden" name="_token" value="{{csrf_token()}}"> 12 13 <!--↓↓名前↓↓--> 14 <div class="form-group"> 15 <label for="name" class="control-label col-sm-2">名前:</label> 16 <div class="col-sm-10"> 17 <input type="text" name="name" id="name" value="{{ old('name') }}" class="form-control" placeholder="名前を文字を入力してください" autofocus> 18 @if($errors->has('name')) 19 <p class="text-danger" style="margin-bottom: 30px;">{{ $errors->first('name') }}</p> 20 @endif 21 <!--/.col-sm-10--></div> 22 <!--/.form-group--></div> 23 <!--↑↑名前↑↑--> 24 25 <!--↓↓年齢↓↓--> 26 <div class="form-group"> 27 <label for="age" class="control-label col-sm-2">年齢:</label> 28 <div class="col-sm-10"> 29 <input type="number" name="age" id="age" value="{{ old('age') }}" class="form-control" placeholder="年齢を入力してください" autofocus> 30 @if($errors->has('age')) 31 <p class="text-danger" style="margin-bottom: 30px;">{{ $errors->first('age') }}</p> 32 @endif 33 <!--/.col-sm-10--></div> 34 <!--/.form-group--></div> 35 <!--↑↑年齢↑↑--> 36 37<button class="btn btn-lg btn-primary btn-block" type="submit">送信</button> 38</form> 39@endsection
更新のviewです。
php
1@extends('layouts.default') 2@section('title', '編集ページ') 3@section('content') 4 5<p>{{$message}}</p> 6<form class="form-horizontal" role="form" method="post" action="{{url('/article',$data->id)}}"> 7<input type="hidden" name="_token" value="{{csrf_token()}}"> 8{{-- 隠しフィールド --}} 9<input type="hidden" name="_method" value="PATCH"> 10 11 <!--↓↓名前↓↓--> 12 <div class="form-group"> 13 <label for="name" class="control-label col-sm-2">名前:</label> 14 <div class="col-sm-10"> 15 <input type="text" name="name" value="{{ old('name', $data->name) }}" id="name" class="form-control" placeholder="名前を文字を入力してください" autofocus> 16 @if($errors->has('name')) 17 <p class="text-danger" style="margin-bottom: 30px;">{{ $errors->first('name') }}</p> 18 @endif 19 <!--/.col-sm-10--></div> 20 <!--/.form-group--></div> 21 <!--↑↑名前↑↑--> 22 23 <!--↓↓年齢↓↓--> 24 <div class="form-group"> 25 <label for="age" class="control-label col-sm-2">年齢:</label> 26 <div class="col-sm-10"> 27 <input type="number" name="age" id="age" value="{{ old('age', $data->age) }}" class="form-control" placeholder="年齢を入力してください" autofocus> 28 @if($errors->has('age')) 29 <p class="text-danger" style="margin-bottom: 30px;">{{ $errors->first('age') }}</p> 30 @endif 31 <!--/.col-sm-10--></div> 32 <!--/.form-group--></div> 33 <!--↑↑年齢↑↑--> 34 35<button class="btn btn-lg btn-primary btn-block" type="submit">送信</button> 36</form> 37@endsection
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/03/19 08:09
2017/03/19 10:28
退会済みユーザー
2017/03/19 13:56