V
V
Valeriy Donika2015-07-25 01:33:20
Laravel
Valeriy Donika, 2015-07-25 01:33:20

Laravel error 500?

Just started learning the framework. I smoke docks. I can not understand what I'm doing wrong, I've been suffering for two hours already.
There is a post plate, there is a Post model

<?php

namespace App\Models\Post;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'post';
}

There is a controller
<?php

namespace App\Http\PostController;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Post;

class PostController extends Controller
{
    /**
     * Display a listing of the posts.
     *
     * @return Response
     */
    public function index()
    {
        $posts = Post::all();
        return view('post.index', ['posts' => $posts]);
    }

}

there is a corresponding view in the resources.post.index folder.
in routes
Route::get('posts', ['as' => 'posts', 'uses' => '[email protected]']);

Moreover, php storm writes here by hovering over this line $posts = Post::all(); ->
$posts = Post::all(); undefined class. How so? namespaces are normal. I'm trying to do the same in the admin controller
use App\Models\Post;

public function index() {
   $posts = Post::find();
    return view('home' => [$posts] => $posts);
}

admincontroller screen 78572cd241f64ac6a94180ac81761d36.png
I can't figure out if I messed up something in the namespaces or I'm doing something wrong.
Lara version 5.1
The Post model is located in the Models folder
Controller in Http/Controllers

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-07-25
@Valonix

>namespace App\Http\PostController
>namespace App\Models\Post
The namespace does not need to be a class name. Just:

namespace App\Http\Controllers;
namespace App\Models;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question