Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

222
Visualizações
Laravel redirecting to the wrong route

web.php

 Route::get('/gigs/{id}', [GigsController::class, 'info'])->name('clientside.gigs_info');

Route::get('/gigs/create', [GigsController::class, 'create'])->name('clientside.gigs.create');

Controller

public function create()
{
    $categories = Category::select('id', 'name')->get();

    return view('clientview.gigs.create', compact('categories'));
}


public function info($id)
{


    $gig = Gigs::join('users', 'users.id', '=', 'gigs.created_by')
        ->join('categories', 'categories.id', '=', 'gigs.category_id')
        ->select('gigs.*', 'categories.name as category_name', 'users.name as user_name', 'users.surname')
        ->where('gigs.id', '=', $id)
        ->orderBy('name', 'ASC')
        ->firstOrFail();

    return view('clientview.gigs.info', compact('gig'));
}

When I try to click this:

<a class="dropdown-item" href="{{ route('clientside.gigs.create') }}">Create Gigs</a>

When I click this I can observe from DebugBar that it directs to route ('clientside.gigs_info') I think "/create" thinks it is an /{ID} but however, I direct to a different route

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Answer by Michael Mano, Make sure you write on web.php static routes before dynamic.

over 4 years ago · Santiago Trujillo Relatório

0

Just write create route before info route because it is dynamic route (That accept parameter) so always write dynamic route after the static route.

over 4 years ago · Santiago Trujillo Relatório

0

You actually created a dynamic route gigs/{id} so anything that comes after gigs will be called as a parameter of gigs. So to fix this change the order in your web.php like below. So it will search for static route first and then go for dynamic route.

Route::get('/gigs/create', [GigsController::class, 'create'])->name('clientside.gigs.create'); Route::get('/gigs/{id}', [GigsController::class, 'info'])->name('clientside.gigs_info');

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda