Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hayatu89's avatar

NotFoundHttpException in RouteCollection.php line 145

I made a couple of functions to show a single item from a collection. Here's the code below

Model for the collection:

class Story extends Model {

    //
    protected $fillable = ['title', 'body', 'slug'];

    public static function boot()
    {
        parent::boot();

        static::saving(function($model) {
            $model->slug = str_slug($model->title);

            return true;
        });
    }
     protected $dates = ['created_at', 'updated_at'];
}

Here is the controller method to show an article

public function show($id)
    {
        # code...
        $story = \App\Story::findOrFail($id);
        return view('news.show', compact('story'));     
    }

Here Is the route

Route::get('/news/{$id}', 'NewsController@show');

But when I go to this route, I get this Error

NotFoundHttpException in RouteCollection.php line 145:
in RouteCollection.php line 145
at RouteCollection->match(object(Request)) in Router.php line 729
at Router->findRoute(object(Request)) in Router.php line 652
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
at require_once('C:\Users\Hayatu\planetfutsal\public\index.php') in server.php line 21

Can anyone help me find out What's wrong? Thanks

0 likes
2 replies
zachleigh's avatar

How do you go to the route? Show us your view.

hayatu89's avatar

This is the index.blade.php

@extends('app')

@section('content')
<div class="container" >
    <div class="row" style="padding:4px;">
        @if($stories)
        <div class="page-header " style="margin-bottom:40px; ">
              <h1 style="border-bottom: 4px solid #EDA815; color: #EDA815;">News</h1>
            </div>  
        <div class="col-md-8">                                  
            <table class="table table-hover" style="color:#EDA815">         
                @foreach($stories as $story)
                <tr>
                    <td><h4><a href="/news/{{$story->id}}">{{$story->title}}</a></h4></td>  
                    <td>{{$story->created_at->diffForHumans()}} </td>                                   
                </tr>                   
                @endforeach
            </table>
            @if(Auth::user())
                <div class="col-md-2"><a  class="btn btn-primary" href="/news/create">New Article</a></div> 
            @endif      
        </div>                  
        @endif
        <div class="col-md-4">
            <img src="/uploads/ad_right.png" width="100%">
        </div>              
    </div>  
</div>  
@endsection

This is the show.blade.php

@extends('app')

@section('content')
<div class="container">
    <div class="row">
        @if($errors->any())
            <div class="alert alert-danger">
               @foreach($errors->all() as $error)
                    <strong>{{ $error}}</strong>
                @endforeach
           </div>
        @endif          
        <div class="page-header " style="margin-bottom:40px">
              <h1>{{$story->title}}</h1>
            </div>
        <div class="col-md-12" style="font-size:13pt">

            <p>{{$story->body}}</p> 
                                                                                        
            <p>Posted on :{{$story->created_at->diffForHumans()}} </p>
        </div>                                          
    </div>  
</div>  
@endsection

Please or to participate in this conversation.