While I use Laravel 5.5
public function index()
{
$posts = Post::orderBy('created_at','desc')->get();
return view('post/index',compact('posts'));
// ['posts' => $posts]);
}
I met a issue:Method 'get' not found in void.Referenced class is not found in subject class
@foreach($posts as $post)
<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/{{$post->id}}" >{{$post->title}}</a></h2>
<p class="blog-post-meta">{{$post->created_at}} by<a href="/user/5">Kassandra Ankunding2</a></p>
<p>{{$post->content}}
<p class="blog-post-meta">赞 0 | 评论 0</p>
</div>
@endforeach
this is the Post class:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
// 表 => posts
class Post extends Model
{
//
/**
* @param $string
* @param $string1
*/
public static function orderBy($string, $string1)
{
}
}
After I remove all the function in Post class,it says:"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pet_shop.posts' doesn't exist (SQL: select * from posts
order by created_at
desc)"
Anybody can help?