laravel入門(いわゆるlaravel入門)の249ページを進めていたところ、次のようなエラーが出ました。
ErrorException (E_ERROR)
未定義のメソッドApp \ Person :: getData()を呼び出します(表示:C:\ Users \ 87saku \ Desktop \ laravelapp \ resources \ views \ person \ index.blade.php)
修正箇所がわかる方いましたら、回答お願いします。
php
1<?php 2 3namespace App\Http\Controllers; 4 5use App\Person; 6use Illuminate\Http\Request; 7 8class PersonController extends Controller 9{ 10 public function index(Request $request) 11 { 12 $items = Person::all(); 13 return view('person.index', ['items' => $items]); 14 } 15 16 public function find(Request $request) 17 { 18 return view('person.find', ['input' => '']); 19 } 20 21 public function search(Request $request) 22 { 23 $min = $request->input * 1; 24 $max = $min + 10; 25 $item = Person::ageGreaterThan($min)->ageLessThan($max)->first(); 26 $param = ['input' => $request->input, 'item' => $item]; 27 return view('person.find', $param); 28 } 29 30 public function add(Request $request) 31 { 32 return view('person.add'); 33 } 34 35 public function create(Request $request) 36 { 37 $this->validate($request, Person::$rules); 38 $person = new Person; 39 $form = $request->all(); 40 unset($form['_token']); 41 $person->fill($form)->save(); 42 return redirect('/person'); 43 } 44}
php
1<?php 2 3namespace App; 4 5use Illuminate\Database\Eloquent\Model; 6use Illuminate\Database\Eloquent\Builder; 7use App\Scopes\ScopePerson; 8 9class Person extends Model 10{ 11 protected $guarded = array('id'); 12 13 public static $rules = array( 14 'name' => 'required', 15 'mail' => 'email', 16 'age' => 'integer|min:0|max:150' 17 ); 18}
php
1<?php 2 3/* 4|-------------------------------------------------------------------------- 5| Web Routes 6|-------------------------------------------------------------------------- 7| 8| Here is where you can register web routes for your application. These 9| routes are loaded by the RouteServiceProvider within a group which 10| contains the "web" middleware group. Now create something great! 11| 12*/ 13//use App\Http\Middleware\HelloMiddleware; 14 15Route::get('hello', 'HelloController@index'); 16Route::post('hello', 'HelloController@post'); 17 18Route::get('person', 'PersonController@index'); 19Route::post('person', 'PersonController@post'); 20 21Route::get('person/find', 'PersonController@find'); 22Route::post('person/find', 'PersonController@search'); 23 24Route::get('person/add', 'PersonController@add'); 25Route::post('person/add', 'PersonController@create');
php
1@extends('layouts.helloapp') 2 3@section('title', 'Person.Add') 4 5@section('menubar') 6 @parent 7 新規作成ページ 8@endsection 9 10@section('content') 11 @if (count($errors) > 0) 12 <div> 13 <ul> 14 @foreach ($errors->all() as $error) 15 <li>{{$error}}</li> 16 @endforeach 17 </ul> 18 </div> 19 @endif 20 <table> 21 <form action = "/person/add" method="post"> 22 {{csrf_field()}} 23 <tr><th>name: </th><td><input type="text" name="name" value="{{old('name')}}"></td></tr> 24 <tr><th>mail: </th><td><input type="text" name="mail" value="{{old('mail')}}"></td></tr> 25 <tr><th>age: </th><td><input type="number" name="age" value="{{old('age')}}"></td></tr> 26 <tr><th></th><td><input type="submit" value="send"></td></tr> 27 </form> 28 </table> 29@endsection 30 31@section('footer') 32copyright 2017 tuyano. 33@endsection