Answer the question
In order to leave comments, you need to log in
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');
Route::get('/', '[email protected]');
Route::resource('/posts', 'BlogPostController');
@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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question