現在以下のURLと」全く同じ状況で、全く同じエラーがでております。
テラテイル類似質問
Personクラス
php
1<?php 2 3namespace App; 4 5use Illuminate\Database\Eloquent\Model; 6 7class Person extends Model 8{ 9 // 10 public function getData() 11 { 12 return $this->id . ': ' . $this->name . ' (' . $this->age . ')'; 13 } 14}
PersonController
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}
index.blade.php(一部のみ抜粋)
blade
1@section('content') 2<table> 3 <tr> 4 <th>Data</th> 5 </tr> 6 @foreach ($items as $item) 7 <tr> 8 <td>{{$item->getData()}}</td> 9 </tr> 10 @endforeach 11</table> 12@endsection
peopleテーブルの定義
php
1<?php 2 3use Illuminate\Support\Facades\Schema; 4use Illuminate\Database\Schema\Blueprint; 5use Illuminate\Database\Migrations\Migration; 6 7class CreatePeopleTable extends Migration 8{ 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('people', function (Blueprint $table) { 17 $table->increments('id'); 18 $table->string('name'); 19 $table->string('mail'); 20 $table->integer('age'); 21 $table->timestamps(); 22 }); 23 } 24 25 /** 26 * Reverse the migrations. 27 * 28 * @return void 29 */ 30 public function down() 31 { 32 Schema::dropIfExists('people'); 33 } 34}
現状
URLで遷移すると以下のエラーが表示されます
error
1Call to undefined method App\Person::getData() (View: /home/vagrant/code/laravelapp/resources/views/person/index.blade.php)
上記のURLではgetDta()メソッドをコントロラーに定義していたみたいですが、私の場合はPersonクラスに定義しているのに同じエラーが出ます。
どこに問題がありますでしょうか。
マイグレーションは成功しており、シーダーでのデータの挿入にも成功しております。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。