I created my first model, run the correct path in browser and get error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Call to undefined method Post::all()
Why is that happening? Im learning laravel with course and the teacher dont have my problem with undefined method :(
I generated model by artisan:
php artisan generate:model Post
My controller:
public function listing()
{
$posts = Post::all();
return View::make('post.listing', compact('posts'));
}
My model:
class Post extends Eloquent {
}
My View:
@extends('layouts.default')
@section('content')
@foreach($posts as $post)
<h1>{{{ $post->title }}}</h1>
@endforeach
@stopassola
How Can I fix this? Of Course I have table named posts in database.
Try this
public function listing()
{
$posts = \App\Post::all();
return View::make('post.listing', compact('posts'));
}
cheers!
I used composer dumpautoload
and found out that have 2 classes named Post.
Problem resolved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.