H
H
HAtan2020-07-24 01:09:19
Laravel
HAtan, 2020-07-24 01:09:19

Error with Route::resource()?

I just started to get into the essence of Laravel, I watched the video course, repeated it, but the cards did not match.
Don't throw stones. In the course they did it on 5.8, and I on the 7th.

There are such routes

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

Route::post('post/', '[email protected]')->name('post.store');

Route::patch('post/show/{id}', '[email protected]')->name('post.update');
Route::delete('post/{id}', '[email protected]')->name('post.destroy');


An attempt to repeat such a resource route failed, but in the course everything happened easily and simply without any manipulation
Route::get('/', '[email protected]');
Route::resource('/posts', 'BlogPostController');


And I get a fatal error
Route [post.show] not defined. (View: C:\xampp\htdocs\laravel\academy\resources\views\posts\index.blade.php)
index.blade.php

@extends('layouts/layout',['title' =>'Главная страница'])
@section('content')
      @if(isset($_GET['search']))
        @if(count($posts)>0)
          <h2>Результаты поиска по запросу <?=$_GET['search'] ?></h2>
          <p class="lead">Всего найдено {{ count($posts) }} постов</p>
        @else
          <h2>По запросу <?=$_GET['search'] ?> ничего не найдено</h2>
          <a href="{{route('post.index')}}" class="btn btn-outline-primary">Ко всем постам</a>
        @endif
      @endif

        <div class="row">
            @foreach($posts as $post)
            <div class="col-6">
                <div class="card">
                    <div class="card-header"><h2>{{ $post->short_title }}</h2></div>
                    <div class="card-body">
                      <div class="card-img" style="background-image: url({{ $post->img ?? asset('img/picca.jpg') }})"></div>
                      <div class="card-author">Автор: {{ $post->name }}</div>
                      <a href="{{ route('post.show', ['id' => $post->post_id]) }}" class="btn btn-outline-primary">Посмотреть пост</a>
                    </div>
                </div>
            </div>
            @endforeach
        </div>
        @if(!isset($_GET['search']))
        {{$posts->links()}}
        @endif
@endsection




Registered route: list
+--------+-----------+-------------------+---- --+-------------------------------------- ---+-----------+
| domain | method | URI | name | action | middleware |
+--------+-----------+--------------------+-------- -------+------------------------------------------ -------+------------+
| | GET|HEAD | / | | App\Http\Controllers\[email protected] | web |
| | GET|HEAD | api/user | | Closure | API |
| | GET|HEAD | posts | posts.index | App\Http\Controllers\[email protected] | web |
| | POST | posts | posts.store | App\Http\Controllers\[email protected] | web |
| | GET|HEAD | posts/create | posts.create | App\Http\Controllers\[email protected] | web |
| | GET|HEAD | posts/{post} | posts.show | App\Http\Controllers\[email protected] | web |
| | PUT|PATCH | posts/{post} | posts.update | App\Http\Controllers\[email protected] | web |
| | DELETE | posts/{post} | posts.destroy | App\Http\Controllers\[email protected] | web |
| | GET|HEAD | posts/{post}/edit | posts.edit | App\Http\Controllers\[email protected] | web |
+--------+-----------+--------------------+-------- -------+------------------------------------------ -------+------------+

I hope for the help of knowledgeable people, this is not an easy task for a beginner

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2020-07-24
@HAtan

Route[ post.show

posts/{post} | posts.show |

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question