エラー文
Non-static method App\Models\Person::getData() should not be called statically.
staticにしていないメソッドを呼び出せない。
対応方法
HelloController.php
use App\Models\Person;
class HelloController extends Controller
{
public function index()
{
$data = Person::getData();
}
}
⬇️
HelloController.php
use App\Models\Person;
class HelloController extends Controller
{
public function index()
{
$person = new Person();
$data = $person->getData();
}
}
このようにモデルのインスタンスを作ってから呼び出すといけます。
モデル側を変更できるときは、functionにstaticをつけることでも対応できるみたいです。
Person.php
class Person extends Model
{
public static function getData()
{
//
参考文献
[Laravel:Non-static methodのエラーが発生した時の対応方法]
(http://raining.bear-life.com/laravel/non-static-method%E3%81%AE%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E7%99%BA%E7%94%9F%E3%81%97%E3%81%9F%E6%99%82%E3%81%AE%E5%AF%BE%E5%BF%9C%E6%96%B9%E6%B3%95)
[PHP5.6で「Non-static method 【x】 should not be called statically in 【y】 on line 【z】」とかいうエラーが出た。]
(http://piyopiyocs.blog115.fc2.com/blog-entry-1133.html)