Php 我不能理解我路线上的问题

Php 我不能理解我路线上的问题,php,laravel,routes,Php,Laravel,Routes,我是新来的拉威尔。我有一个前端和后端为我的应用程序。我已经设置了路线、控制器和其他必要的东西。但每次我点击前端的帖子标题,它就会重定向到后端,什么也不显示。我不知道我的问题在哪里 [它重定向到后端 请从输出文章标题及其链接的视图中向我们展示代码。您还应该查看php artisan route:list以查看是否有冲突的路由。我假设您正在点击backend/blog/{id},但我想知道您的博客id是否确实是字符串而不是递增的数字{{$post->title}中根本没有链接。它根本不应该重定向到

我是新来的拉威尔。我有一个前端和后端为我的应用程序。我已经设置了路线、控制器和其他必要的东西。但每次我点击前端的帖子标题,它就会重定向到后端,什么也不显示。我不知道我的问题在哪里

[它重定向到后端


请从输出文章标题及其链接的视图中向我们展示代码。您还应该查看
php artisan route:list
以查看是否有冲突的路由。我假设您正在点击
backend/blog/{id}
,但我想知道您的博客id是否确实是字符串而不是递增的数字
{{$post->title}
中根本没有链接。它根本不应该重定向到任何东西。@apokryfos,先生,它们是字符串。(@Maheeb您的屏幕截图显示了一个链接。您的
{$post->title}
中没有链接。
    <?php

    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */

    Auth::routes();

    Route::get('/home', 'Backend\HomeController@index');
    Route::get('/', [
        'uses' =>'BlogController@index',
        'as'=>'blog'
        ]);

    Route::get('blog/{post}', [
        'uses' => 'BlogController@show',
        'as'   => 'blog.show'
    ]);
    Route::get('tag/{tag}', [
        'uses' => 'BlogController@tag',
        'as'   => 'tag'
    ]);

    Route::get('category/{category}', [
        'uses' =>'BlogController@category',
        'as'=>'category'
    ]);
    Route::get('author/{author}', [
        'uses' =>'BlogController@author',
        'as'=>'author'
    ]);

    Route::resource('backend/blog/', 'Backend\BlogController');
    Route::resource('backend/categories','Backend\CategoriesController');
    Route::resource('backend/users','Backend\UsersController');

    Route::put('/backend/blog/restore/{blog}',[
        'uses'  =>'Backend\BlogController@restore',
        'as'=>'backend.blog.restore'
        ]);

    Route::delete('/backend/blog/force-destroy/{blog}',[
        'uses'  =>'Backend\BlogController@forceDestroy',
        'as'=>'backend.blog.force-destroy'
    ]);

    Route::get('/backend/users/confirm/{users}', [
        'uses' => 'Backend\UsersController@confirm',
        'as' => 'backend.users.confirm'
    ]);
    <?php

namespace App\Http\Controllers;

use App\Category;
use App\Post;
use App\Tag;
use App\User;
use Illuminate\Http\Request;

class BlogController extends Controller
{
    //
    protected $limit =5;

    public function index(){
        $posts = Post::with('author')
            ->latestFirst()
            ->published()
            ->filter(request('term'))
            ->simplePaginate($this->limit);

        return view("blogs.index", compact('posts'));


    }

    public function category(Category $category){
        $categoryName = $category->title;


        $posts = $category->posts()
                ->with('author')
                ->latestFirst()
                ->published()
                ->simplePaginate($this->limit);
                return view ("blogs.index",compact('posts','categoryName'));


    }

    public function show(Post $post)
    {

        $post->increment('view_count');
        return view("blogs.show",compact('post'));

    }


    public function author(User $author)
    {
        $authorName = $author->name;

        $posts = $author->posts()
            ->with('category')
            ->latestFirst()
            ->published()
            ->simplePaginate($this->limit);

        return view("blogs.index", compact('posts', 'authorName'));
    }

    public function tag(Tag $tag)
    {
        $tagName = $tag->title;

        $posts = $tag->posts()
            ->with('author', 'category')
            ->latestFirst()
            ->published()
            ->simplePaginate($this->limit);

        return view("blogs.index", compact('posts', 'tagName'));
    }





}
@extends('layouts.main')

@section('content')

    <div class="container">
        <div class="row">
            <div class="col-md-8">
                @if (! $posts->count())
                    <div class="alert alert-warning">
                        <p>Nothing Found</p>
                    </div>
                @else
                    @include('blogs.alert')

                    @foreach($posts as $post)

                        <article class="post-item">
                            @if ($post->image)
                                <div class="post-item-image">
                                    <a href="{{ route('blog.show', $post->slug) }}">
                                        <img src="{{ $post->image?asset('/images/img/' . $post->image):'http://placehold.it/400x400' }}" alt="">
                                    </a>
                                </div>
                            @endif

                            <div class="post-item-body">
                                <div class="padding-10">
                                    <h2><a href="{{ route('blog.show', $post->slug) }}">{{ $post->title }}</a></h2>
                                    {!! $post->excerpt_html !!}
                                </div>

                                <div class="post-meta padding-10 clearfix">
                                    <div class="pull-left">
                                        <ul class="post-meta-group">
                                            <li><i class="fa fa-user"></i><a href="{{ route('author', $post->author->slug) }}"> {{ $post->author->name }}</a></li>
                                            <li><i class="fa fa-clock-o"></i><time> {{ $post->date }}</time></li>
                                            <li><i class="fa fa-folder"></i><a href="{{ route('category', $post->category->slug) }}"> {{ $post->category->title }}</a></li>
                                            <li><i class="fa fa-tag"></i>{!! $post->tags_html !!}</li>
                                            <li><i class="fa fa-comments"></i><a href="#">4 Comments</a></li>
                                        </ul>
                                    </div>
                                    <div class="pull-right">
                                        <a href="{{ route('blog.show', $post->slug) }}">Continue Reading &raquo;</a>
                                    </div>
                                </div>
                            </div>
                        </article>

                    @endforeach

                @endif

                <nav>
                    {{ $posts->appends(request()->only(['term']))->links() }}
                </nav>
            </div>

            @include('layouts.sidebar')
        </div>
    </div>

@endsection
@extends('layouts.main')

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-8">
                <article class="post-item post-detail">
                    {{--@if (($post->image))--}}
                        <div class="post-item-image">

                                <img src="{{ $post->image?asset('/images/img/' . $post->image):'http://placehold.it/400x400' }}" alt="">

                        </div>
                    {{--@endif--}}


                    <div class="post-item-body">
                        <div class="padding-10">
                            <h1>{{$post->title}}</h1>

                            <div class="post-meta no-border">
                                <ul class="post-meta-group">
                                    <li><i class="fa fa-user"></i><a href="{{route('author',$post->author->slug)}}"> {{$post->author->name}}</a></li>
                                    <li><i class="fa fa-clock-o"></i><time>{{$post->date}}</time></li>
                                    <li><i class="fa fa-folder"></i><a href="{{route('category',$post->category->slug)}}"> {{$post->category->title}}</a></li>
                                    <li><i class="fa fa-tag"></i>{!! $post->tags_html !!}</li>
                                    <li><i class="fa fa-comments"></i><a href="#">4 Comments</a></li>
                                </ul>
                            </div>

                        {!!  $post->body_html!!}
                        </div>
                    </div>
                </article>

                <article class="post-author padding-10">
                    <div class="media">
                        <div class="media-left">
                            <?php $author = $post->author?>
                            <a href="{{route('author', $author->slug)}}">
                                <img alt="{{$author->name}}" width="100" height="100" src="{{$author->gravatar()}}" class="media-object">
                            </a>
                        </div>
                        <div class="media-body">
                            <h4 class="media-heading"><a href="{{route('author',$author->slug)}}">{{$author->name}}</a></h4>
                            <div class="post-author-count">
                                <a href="{{route('author',$author->slug)}}">
                                    <i class="fa fa-clone"></i>
                                    <?php $postCount = $author->posts()->published()->count()?>
                                    {{$postCount}} {{str_plural('post', $postCount)}}
                                </a>
                            </div>
                           {!! $author->bio_html !!}
                        </div>
                    </div>
                </article>



                {{--Comments here--}}
            </div>
            @include('layouts.sidebar')

        </div>

    </div>

@stop
 <?php

namespace App\Providers;

use App\Post;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;

//use Symfony\Component\Routing\Annotation\Route;
//use Symfony\Component\Routing\Route;

//use Symfony\Component\Routing\Router;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

       parent::boot();

        Route::bind('post',function ($slug){

        return Post::published()->where('slug', $slug)

            ->first();
            });

    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapWebRoutes();

        //
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}
public function show(Post $post) <-- this need full object for getting result
    {

        $post->increment('view_count');
        return view("blogs.show",compact('post'));

    }
public function show($slug){
  $post = Post::where('slug', $slug)->firstorfail();
  $post->increment('view_count');
  return view("blogs.show",compact('post'));
}