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

106
Visualizações
Route isn't redirecting me to the correct page. It just shows me the same page but the url changes

I've made a blog template but I having trouble making the routes. When I click on the link, it should redirect me to the article page. Instead it just redirects me to the same page/same exact location. Here's my code:

<section id="about" class="ts-block" >
    <div id="cards_landscape_wrap-2">
    <div class="container">
        <div class="row">
        @foreach($blogs as $blog)
            <div class="col-lg-4">
                <a href={{route("blogs.show",$blog->slug)}}>
                    <div class="card-flyer"  >
                        <div class="text-box">
                            <div class="image-box ">
                                <img src="{{'/images/blogs/'.$blog->image}}" alt="{{$blog->title}}" class="img-fluid rounded mx-auto d-block" width="100%"/>
                            </div>
                            <div class="text-container">
                                <h6>{{$blog->title}}</h6>
                                <p style="max-width: 18rem;"class="ts-opacity__50">{{Str::limit($blog->description,100)}}</p>
                            </div>
                            <div class="card-footer">
                                        <span class="text-primary font-weight-bold">Read</span>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
            @endforeach
        </div>
    </div>
    </div>
    </section>    

BlogController :

public function getArticles()
{
    return view('blog')->with([
        'blogs' => Blog::all(),
    ]);
}

Routes :

Route::get('/blog/', [App\Http\Controllers\BlogController::class, 'index'])->name('blog');
Route::get('blogs/','App\Http\Controllers\BlogController@getArticles')->name('blogs.show');
Route::get('/admin/blog', 'App\Http\Controllers\BlogController@getBlog')->name('admin.blog');
Route::resource('/blog','App\Http\Controllers\BlogController');

The routes that supposed to be redirecting me to another page is the 2nd one with BlogController@getArticles. The other routes are fine a have no problem.

Can someone kindly show me what I did wrong ?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

First, change your route by :

Route::get('/blogs/{slug}','App\Http\Controllers\BlogController@getArticles')->name('blogs.show');

Then, in your function :

public function getArticles($slug)
{
    return view('blog')->with([
        'blogs' => Blog::firstWhere('slug', $slug);
    ]);
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Well your question is little confusing, because that's the expected result from the code.

You are calling the 'blogs.show' route, which redirects you to the blogs page. If you want to create a seperate page for every article, you can use Dynamic Rounting in laravel.

All you have to do is:

in web.php:

Route::get('blogs/{slug}', 'App\Http\Controllers\BlogController@getArticle')->name('article.show');

and in your controller:

public function getArticles($slug)
{

    $article = Blog::where('slug', $slug)->first();
    return view('article')->with([
        'article' => $article,
    ]);
}

After that, <a href={{route("article.show",$blog->slug)}}></a> will work.

about 4 years ago · Juan Pablo Isaza 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