artisticre's avatar

Why Am I Getting This Error?

I know it is probably something pretty simple but for the life of me I cannot figure out why I get this error:

The requested resource /blog was not found on this server.

Route

Route::resource('/blog','BlogController');

BlogController

public function index()
    {
        return view('blog.index');
    }

Blog.index

@extends('layouts.bloglayout')

@section('content')
TEST BLOG PAGE
@endsection

bloglayout

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('blog/js/app.js') }}" defer></script>

      <!-- Styles -->
  <!-- Custom styles for this template -->
  <link href="blog/css/clean-blog.min.css" rel="stylesheet"></head>
<body>
    @include('inc.navbar')
   @include('inc.jumbotron') 
    <div id="app">
        

        <main class="py-4">
            <div class="container">
            @include('inc.alerts')
            
            @yield('content')
        </div>
        </main>
    </div>
    <script src="blog/js/clean-blog.min.js"></script>
</body>
</html>
0 likes
7 replies
MichalOravec's avatar

Problem is that in your public folder you have a blog folder.

1 like
Sergiu17's avatar

Because you have a blog folder inside public folder

artisticre's avatar

so how do I do a seperate template for one page?

jlrdw's avatar

@artisticre I do use blade sometimes, but I really don't use resource controllers.

Is that all that's needed?

public function index()
    {
        return view('blog.index');
    }

Or are you missing something, just checking.

Edit: wouldn't blog index go at

resources/views/blog/index.blade.php

Are would it be different for resource controller usage. What do you guys mean he has a Blog folder under public.

Sergiu17's avatar
Sergiu17
Best Answer
Level 60

@artisticre you have to rename the blog folder from your public directory to something else, when you hit localhost:8000/blog apache or nginx scans the public directory first, and if there's a match it tries to load index.php, or index.html or index.htm inside that folder, and because you don't have index.php - you get: The requested resource /blog was not found on this server.

Edit*

@jlrdw I tried to explain above

MichalOravec's avatar

@artisticre Just move your assets to the jsand css folder.

And if you need it separated in the blog folder do it like css/blog/clean-blog.min.css. But in my opinion it's not necessary.

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <link href="{{ asset('css/blog/clean-blog.min.css') }}" rel="stylesheet">
</head>
<body>
    @include('inc.navbar')

    @include('inc.jumbotron')

    <div id="app">
        <main class="py-4">
            <div class="container">
                @include('inc.alerts')

                @yield('content')
            </div>
        </main>
    </div>

    <script src="{{ asset('js/blog/app.js') }}" defer></script>

    <script src="{{ asset('js/blog/clean-blog.min.js') }}"></script>
</body>
</html>
jlrdw's avatar

@sergiu17 thanks I see now I didn't catch it at first he had a site name blog and a folder Under The View with blog also.

Probably localhost:8000/blog/blog/index then.

I know something like that works because I've used it, but non resource controllers.

I stick with normal regular routes.

1 like

Please or to participate in this conversation.