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

Amalmax's avatar

How to fix NotFoundHttpException No query results for model [App\Upload] 8

I am working with Laravel 5.6 and MySQL DB. in my application I have some form data edit link from vehicles table, My edit link is this,

{{route('vehicles.edit',$vehicule->id.'/edit/')}}" >Edit</a>

and I have vehicle images show table as uploads and relationship between Vehicle model and Upload model is like this, vehicle model

public function uploads()
    {
        return $this->hasMany(Upload::class);
    }

upload model

 public function vehicle()
    {
        return $this->belongsTo(Vehicle::class);
    }

and my vehicle edit route is like this,

Route::get('myads/{id}/edit', [
    'uses' => '\App\Http\Controllers\VehicleController@edit',
    'as'=> 'vehicles.edit'
]);

My edit blade file vehicle images showing as this,

@foreach( $vehicles-> uploads as $upload)
                        
                    <img id="preview"
                         src="{{asset((isset($upload) && $upload->resized_name!='')?'images/'.$upload->resized_name:'images/noimage.png')}}"
                         height="200px" width="200px"/>
                    <input class="form-control" style="display:none" name="files[]" type="file" id="files" name="_token" value="{{ csrf_token() }}" enctype="multipart/form-data">
                    <br/>
                    <!-- <a href="javascript:changeProfile();">Add Image</a> | -->
                    <!-- <a style="color: red" href="javascript:removeImage()">Delete</a>
                    <input type="hidden" style="display: none" value="0" name="remove" id="remove"> -->
               <a href="/myads/{{$upload->id}}/editimage">Edit Image</a>|

               <a class="button is-outlined" href="/myads/{{$upload->id}}/delete" onclick="return confirm('Are you sure to want to delete this record?')" >Delete</a></td>

                  <hr>
                   @endforeach
                    @endif

but when i click above edit link I got following error,

NotFoundHttpException

No query results for model [App\Upload] 8  //8 this is  vehicle id

how can I fix this problem?

0 likes
8 replies
_Artak_'s avatar
// route
Route::get('myads/{id}/edit'`


 <a href="/myads/{{$upload->id}}/editimage">Edit Image</a>|
 

change to


<a href="/myads/{{$upload->id}}/edit">Edit Image</a>|

Amalmax's avatar

@Artak it is not change same result here......

Ishatanjeeb's avatar

Your named routes should be look like this-

Route::get('myads/{id}/edit', [
    'as'=> 'vehicles',
        'uses' => 'VehicleController@edit'
]);
Tray2's avatar

What does your edit method in your controller look like? That message is probably due to there not being any record with the id of 8 in your table.

Snapey's avatar

this

{{route('vehicles.edit',$vehicule->id.'/edit/')}}" >Edit</a>

is not the right way to use the route command. you give it the route NAME as the first parameter and if there is a single parameter in the route then it comes as the second parameter

{{route('vehicles.edit',$vehicule->id)}}" >Edit</a>

Please or to participate in this conversation.