前提・実現したいこと
laravelの教本に従って記述しているのですが、エラーが出てしまいます。
発生している問題・エラーメッセージ
Call to undefined method Faker\Provider\zh_CN\Person::orderBy()
該当のソースコード
//HelloController.php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Http\Requests\HelloRequest; use Validator; use Illuminate\Support\Facades\DB; use Faker\Provider\zh_CN\Person; class HelloController extends Controller { public function index(Request $request) { $sort = $request->sort; //$items = DB::table('people')->simplePaginate(5); // ->orderBy($sort, 'asc'); $items = Person::orderBy($sort, 'asc')->simplePaginate(5); $param = ['items' => $items, 'sort' => $sort]; return view('hello.index', $param); } public function index(Request $request) { $sort = $request->sort; //$items = DB::table('people')->simplePaginate(5); // ->orderBy($sort, 'asc'); $items = Person::orderBy($sort, 'asc')->simplePaginate(5); $param = ['items' => $items, 'sort' => $sort]; return view('hello.index', $param); }
//index.blade.php @extends('layouts.helloapp') <style> .pagination {font-size: 10pt;} .pagination li {display: inline-block;} tr th a:link {color: white;} tr th a:visited {color: white;} tr th a:hover {color: white;} tr th a:active { color: white;} </style> @section('title','Index') @section('menubar') @parent インデックスページ @endsection @section('content') <table> <tr> <th><a href="/hello?sort=name">name</a></th> <th><a href="/hello?sort=mail">mail</a></th> <th><a href="/hello?sort=age">age</a></th> </tr> @foreach ($items as $item) <tr> <td>{{$item->name}}</td> <td>{{$item->mail}}</td> <td>{{$item->age}}</td> </tr> @endforeach </table> {{ $items->appends(['sort' => $sort])->links() }} @endsection @section('footer') copyright 2017 tuyano. @endsection
試したこと
localhost/helloにアクセスしてエラー。
localhost/hello?sort=nameにアクセスしてエラー。
localhost/Personでデータベースの中身は表示されている。
パラメータはGetDataに表示されている。
補足情報(FW/ツールのバージョンなど)
visual studio codeで作成。
php7
Laravel5.8.18です。よろしくお願いします
回答1件
あなたの回答
tips
プレビュー