B
B
bwylla2020-09-05 02:02:14
Laravel
bwylla, 2020-09-05 02:02:14

Why do all links change their link?

Goodnight.
I'm doing a shit blog. Added 2 pages (main and categories) and everything works fine, added a page for viewing an article by id, registered a controller and a route, I did the same before, but now on the post page, all links (even static ones) in href are added the word "post". Another interesting thing is that the links leading to css files have not been changed.

//web.php

Route::get('/', '[email protected]')->name('index');
Route::get('/post/{id}', '[email protected]')->name('post');
Route::get('/{category}', '[email protected]')->name('category');

//controllers
class MainController extends Controller
{
    public function index() {
        $posts = Post::get();
        return view('index', compact('posts'));
    }

    public function category($code) {
        $category = Category::where('code', $code)->first();
        if (is_null($category)) {
            abort('404');
        }
        return view('category', compact('category'));
    }

    public function post($id) {
        $post = Post::findOrFail($id);
        return view('post', compact('post'));
    } 
}

#template
@extends('layouts/master')
@section('content')
    {{ $post->name }}
@endsection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Shalin, 2020-09-05
@restalpo

Show how you generate links in a view. If via route('post'), then the address will contain post, because it is specified in the router. If you make links manually, do you remember to put a slash at the beginning so that it comes from the root, and not from the post? In the case of a css file, then for sure there is a call {{ mix(css.css) }}, which means that the correct links will be displayed, no matter what.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question