Monday, March 13, 2017

Strange error "Routes not defined"

I'm learning Laravel 5.4 and I can't get around this. I've added two routes in my view blade like this

<a href="" class="btn btn-primary">Write post</a>

Then in my route web.php file I have

Route::resource('/backend/blog', 'Backend\BlogController');

In HomeController@index where I loading index page which has the button above, like this

<?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Post;

class BlogController extends BackendController
{
    protected $limit = 5;

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts     = Post::with('category', 'author')->latest()->paginate($this->limit);
        $postCount = Post::count();
        return view("backend.blog.index", compact('posts', 'postCount'));
    }
       ...

}

HomeController in Backend dir holds

<?php

namespace App\Http\Controllers\Backend;

use App\Http\Requests;
use Illuminate\Http\Request;

class HomeController extends BackendController
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('backend.home');
    }
}

backend.home has the a href above which generates the error.. Why this happen?

Full error message

ErrorException in UrlGenerator.php line 304:
Route [backend.blog.create] not defined. (View: /var/www/blog/resources/views/backend/home.blade.php)



via VLS

Advertisement