我正在学习如何做一个简单的Laravel应用程序,一个社交网络,我遇到了一个错误
class View: UIView {
private let statusBarUnderlay = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
statusBarUnderlay.backgroundColor = UIColor.black
addSubview(statusBarUnderlay)
}
required init?(coder aDecoder: NSCoder) {
fatalError("Storyboards are incompatible with truth and beauty.")
}
override func layoutSubviews() {
super.layoutSubviews()
statusBarUnderlay.frame = UIApplication.shared.statusBarFrame
}
}
我的PostController.php是这样的:
[Fri Aug 26 00:46:30 2016] PHP Fatal error: Class 'App\Http\Controllers\Post' not found in C:\xampp\htdocs\social-network\app\Http\Controllers\PostController.php on line 13
我的帖子模型是:
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class PostController extends Controller
{
public function postCreatePost(Request $request)
{
$post = new Post();
$post->body = $request['body'];
$request->user()->posts()->save($post);
return redirect()->route('dashboard');
}
}
我不明白我做错了什么。任何人都可以帮我弄清楚错误。提前致谢
答案 0 :(得分:2)
您需要添加模型。
尝试在命名空间
之后在控制器中添加以下行use App\Post;
这是错误消息的确切告诉你的内容。
答案 1 :(得分:1)
您忘了使用告诉您的控制器使用App\Post
:
<?php
namespace App\Http\Controllers;
use App\User;
use App\Post;
use Illuminate\Http\Request;
class PostController extends Controller{
public function postCreatePost(Request $request){
$post = new Post();
$post->body = $request['body'];
$request->user()->posts()->save($post);
return redirect()->route('dashboard');
}
}
另外,通常最好确保在添加新类后运行composer dump-autoload
。