路线不工作

时间:2016-08-09 10:48:12

标签: php laravel laravel-5 laravel-routing

我正在按照教程查看单个帖子,但由于某种原因它看不到找到的考试我不知道缺少什么

  

RouteCollection.php第161行中的NotFoundHttpException:

我正在尝试通过此网址

访问路线
http://domain.app/admin/blog/post/2&admin

查看路径

  

观看次数 - > admin - >博客 - > single.blade.php

路线

Route::group(['prefix' => '/admin'], function(
Route::get('/blog/post/{post_id}&{$end}', [
    'uses'  => 'PostController@getSinglePost',
    'as'    => 'admin.blog.post'
]);
});

控制器

    <?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\Catgory;

class PostController extends Controller {
public function getSinglePost($post_id, $end = 'frontend') {
    $post = Post::find($post_id);

    if(!$post) {
        return redirect()->route('blog.index')->with(['fail' => 'Post not found']);
    }

    return view ($end, '.blog.single', ['post' => $post]);
}
}

2 个答案:

答案 0 :(得分:1)

尝试 / 而不是&amp; ...

Route::group(['prefix' => '/admin'], function(
Route::get('/blog/post/{post_id}/{end}', [
    'uses'  => 'PostController@getSinglePost',
    'as'    => 'admin.blog.post'
]);
});

你的网址应该像......

http://domain.app/admin/blog/post/2/admin

AND

return view ($end.'.blog.single', ['post' => $post]);//remove , and add .

答案 1 :(得分:1)

你可以这样试试吗?

<强> ROUTE

<?php 

    // SHOULD MATCH SOMETHING LIKE: /admin/blog/post/1/admin
    // OR:                          /admin/blog/post/1/frontend
    Route::group(['prefix' => '/admin'], function(
        Route::get('/blog/post/{post_id}/{end}', [
            'uses'  => 'PostController@getSinglePost',
            'as'    => 'admin.blog.post'
        ]);
    });

<强> CONTROLLER

<?php

    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Post;
    use App\Catgory;

    class PostController extends Controller {
        public function getSinglePost($post_id, $end = 'frontend') {
            $post = Post::find($post_id);

            if(!$post) {
                return redirect()->route('blog.index')->with(['fail' => 'Post not found']);
            }
            // YOU ARE CONCATENATING SO NO NEED FOR COMMA...
            return view($end . '.blog.single', ['post' => $post]);
        }
    }