Skip to content
Advertisement

Laravel route problem redirects 404 error

I have a problem, I made a support system, and when I want to enter the page where I watch the ticket, I will get 404 not found. Basically the route is that of the id in the database.

Routes:

Route::get('/viewTickets', 'TicketController@view_MyTickets')->name('viewTickets');

Route::get('/viewTickets/{ticket}', 'TicketController@view_MyTicketUpdate')->name('updateTicket');

Route::post('/viewTickets/{ticket}', 'TicketController@update_MyTicket');

Controller:

public function view_MyTickets() {
    $tickets = Ticket::latest()->get();
    return view('viewTickets', compact('tickets'));
}

public function view_MyTicketUpdate() {
    $tickets = Ticket::latest()->get();
    return view('updateTicket', compact('tickets'));
}

View:

<tbody>
             @foreach($tickets as $ticket)
                <tr>
                    <td>{{$ticket->id}}</td>
                    <td>{{$ticket->user_id}}</td>
                    <td>{{$ticket->title}}</td>
                    <td>{{$ticket->category}}</td>
                    <td>{{$ticket->status}}</td>
                    <td>
                    <form>
                        <a href="{{ $ticket->id }}" class="view" title="View" data-toggle="tooltip"><i class="material-icons"></i></a>
                        <a href="{{ $ticket->id }}"lass="edit" title="Edit" data-toggle="tooltip"><i class="material-icons"></i></a>

                    </td>
                </form>
                </tr>
             @endforeach
        </tbody>

I really don’t understand the problem, a way to solve and did not receive error 404? Btw, I read the other topics and I couldn’t find a solution.

Advertisement

Answer

The link you are setting in the href attribute is only the ticket id, but it should be, for example, “/viewTickets/1”

Try to put this:

href="{{route('updateTicket', ['ticket' => $ticket->id])}}"
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement