Answer the question
In order to leave comments, you need to log in
Error with Route::resource() in Laravel?
The error is
Missing required parameters for [Route: post.show] [URI: post/{post}]. (View: E:\ospanel\OSPanel\domains\akademka\resources\views\posts\index.blade.php)
when changed routes from original value
Route::get('post/', '[email protected]')->name('post.index');
Route::get('post/show/{id}', '[email protected]')->name('post.show');
Route::get('post/create', '[email protected]')->name('post.create');
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::resource('/post', 'PostController');
@extends('layouts.layout')
@section('content')
@if(isset($_GET['search']))
@if( count($posts)>0)
<h2>Результат поиска:</h2>
<p class="lead">Всего найдено {{ count($posts) }} постов</p>
@else
<h2>По запросу <?php echo $_GET['search']?> ничего не найдено</h2>
<a class="btn btn-outline-primary" href="{{ route('post.index') }}"> Все посты </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/who.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
Resource routes do not need to pass parameter names.
Those. either the resource or its identifier if the resource does not exist. Laravel will automatically connect and the controller will already have the required resource
route('posts.show', $post)
public function show(Post $post)
{
dd($post);
}
protected $primaryKey = 'slug';
Route::resource('posts', 'PostController');
The easiest way is to route
use action
and pass an instance of the model to it instead:
action('[email protected]', $post);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question