Redirect fault Laravel

Asked

Viewed 136 times

1

Expensive,

Can you help me with this portable redirect? I created a method where it re-evaluates the data and redirects, on the other hand when redirecting I get the Route error [clima.consenso.visual.ID] not defined, only that I defined the routes.

Imagery inserir a descrição da imagem aqui

    //Redireciona
public function redirect( Request $request, Pesquisa $pesquisa )
{
    $jaFeito = Consenso::where( 'pesquisa_id', $pesquisa->id )->count() > 0;

    if ($jaFeito) {
        return redirect()->route( 'clima.consenso.visual.'.$pesquisa->id );
    }
    return redirect()->route( 'clima.consenso.show' );
}

Route

        //Grupo consenso
    $router->group( [ 'prefix' => 'consenso', 'as' => 'consenso.' ],
        function ( $router ) {
            /** @var \Illuminate\Routing\Router $router */
            $router->get( '/', [ 'uses' => 'ConsensoController@index', 'as' => 'index' ] );

            $router->get( '/pesquisa/{clima_pesquisa}', [
                'uses' => 'ConsensoController@show',
                'as'   => 'show'
            ] );
            $router->post( '/pesquisa/{clima_pesquisa}', [
                'uses' => 'ConsensoController@store',
                'as'   => 'store'
            ] );
            $router->get( '/visual/{clima_pesquisa}', [
                'uses' => 'ConsensoController@visual',
                'as'   => 'visual'
            ] );

            $router->get( '/redirect/{clima_pesquisa}', [
                'uses' => 'ConsensoController@redirect',
                'as'   => 'redirect'
            ] );
        }
    );

View

        @forelse($pesquisas as $pesquisa)
        <tr>
            <th scope="row">
                <a href="{{ route('clima.consenso.redirect', compact('pesquisa')) }}">{{$pesquisa->id}}</a>
            </th>
            <td>
                <a href="{{ route('clima.consenso.redirect', compact('pesquisa')) }}">{{$pesquisa->matricula}}</a>
            </td>
            <td>
                <a href="{{ route('clima.consenso.redirect', compact('pesquisa')) }}">{{mb_convert_case($pesquisa->nome,MB_CASE_TITLE , 'UTF-8' )}}</a>
            </td>
            <td>{{ $pesquisa->updated_at->format('d/m/Y H:i') }}</td>
            <td>
                <button
                        type="button" class="btn">
                    <a href="{{ route('clima.consenso.show', compact('pesquisa')) }}">Avaliar</a>
                </button>
            </td>
        </tr>

1 answer

3


The error is correct, the route clima.consenso.visual.1127 does not exist at all. The existing route is clima.consenso.visual that receives a parameter clima_pesquisa.

To redirect a Response for a named route just use redirect('nome.da.rota', ['parametros' => 'da rota']);

In your case it would be:

return redirect()->route( 'clima.consenso.visual', ['clima_pesquisa' => $pesquisa->id]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.