salama2121 salama2121 -4 years ago 164
PHP Question

Laravel Controller error

I'm learning how to do a simple Laravel app, an social network and I came across an error

[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

My PostController.php is this:

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'];
return redirect()->route('dashboard');


My Post model is this:


namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model

public function user(){
return $this->belongsTo('App\User');

I don't understand what I did wrong. Can anyone help me figure out the error. Thanks in advance

Answer Source

You need to add the model.

Try to add following line in your controller after namespace

use App\Post;

This is what the error message exactly telling you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download