Russo
Russo

Reputation: 13

Laravel 5.8 Routed page not found 404 error

I am new to Laravel. I am learning Laravel from tutorial and I drive into one problem which I can't solve.
I think I have problem somewhere into Routing, but I can't find it
Funny thing is that if the href is {{route('tag.create'}}, then it goes to creating page, but when I need to use ID it's not working... I had same functionality for posts and categories, but everything worked fine for those two. So I really need your help to see what I can't see. I have these files:

index.blade.php:

@extends('layouts.app')

@section('content')

    <div class="card">
        <div class="card-body">
            <table class="table table-hover">
                <thead>
                    <th>
                        Tag name
                    </th>

                    <th>
                        Delete
                    </th>
                </thead>
                <tbody>
                    @if($tags->count()>0)
                        @foreach($tags as $tag)
                            <tr>
                                <td>
                                    {{$tag->tag}}
                                </td>
                                <td>
                                    <a href="{{route('tag.delete', ['id' =>$tag->id])}}" class="btn btn-danger btn-xs"><i class="fa fa-trash" aria-hidden="true"></i></a>
                                </td>
                            </tr>
                        @endforeach
                    @else
                        <tr>
                            <th colspan="5" class="text-center">
                                No tags yet
                            </th>
                        </tr>
                    @endif
                </tbody>
            </table>    

        </div>
    </div>


@stop

web.php - this is the place where I define routes for tags for TagsController.php:

//Tags
    Route::get('/tags',[
        'uses'=>'TagsController@index',
        'as'=> 'tags'
    ]);

    Route::post('/tag/update/{$id}',[
        'uses'=>'TagsController@update',
        'as'=> 'tag.update'
    ]);

    Route::get('/tag/create',[
        'uses'=>'TagsController@create',
        'as'=> 'tag.create'
    ]);
    Route::post('/tag/store',[
        'uses'=>'TagsController@store',
        'as'=> 'tag.store'
    ]);
    Route::get('/tag/delete/{$id}',[
        'uses'=>'TagsController@destroy',
        'as'=> 'tag.delete'
    ]);

TagsController.php - at first I tried to destroy the element, then I tried to return create view(because when I go through /tag/create rout everything works), but neither worked here

public function destroy($id)
    {
        return view ('admin.tags.create');
        /*
        Tag::destroy($id);

        Session::flash('success', 'Tag deleted succesfully');

        return redirect()->back();*/
    }

Upvotes: 1

Views: 2598

Answers (2)

Sreedev R
Sreedev R

Reputation: 1

Please change the parameters in the route setup in web.php from $id to id. I should solve your issue.

Eg: Route::get('/tag/delete/{id}',[ 'uses'=>'TagsController@destroy', 'as'=> 'tag.delete' ]);

Thanks !!.

Upvotes: 0

Khaldoun Nd
Khaldoun Nd

Reputation: 1466

I believe that you should set the route to Route::get('/tag/delete/{id}',[ 'uses'=>'TagsController@destroy', 'as'=> 'tag.delete' ]); because in your case you are telling the route to expect a variable called $id

Upvotes: 1

Related Questions