For some reason I can't get this to work, I've been racking my brain for two days now trying to figure it out and it's just not happening.
This is my route group I have setup...
// Admin Panel Routes Group
Route::group(['prefix' => 'admin', 'middleware' => ['auth']], function() {
Route::get('/', ['uses' => 'Admin\AdminController@index'])->name('admin');
Route::get('posts', ['uses' => 'PostController@index'])->name('posts-list');
Route::delete('post/delete/{id}', ['uses' => 'PostController@delete'])->name('post-delete');
Route::get('posts/new', ['uses' => 'PostController@newPost'])->name('post-new');
Route::post('posts/create', ['uses' => 'PostController@createPost'])->name('post-create');
Route::post('posts/upload', ['uses' => 'PostController@fileUpload'])->name('post-upload');
Route::get('post/{slug}/edit', ['uses' => 'PostController@editPost'])->name('post-edit');
});
As you can see, I have managed to use a parameter in the DELETE request for posts perfectly fine. The function for the DELETE request in the PostController works as expected and reads the parameter from the URL and deletes the record from the database.
The issue may lie within the PostController 'editPost' function, this is a function I intend to use to fetch the post from the database via a slug, using that to determine which post it is and then loading the form with the data.
public function editPost($slug) {
$post = Post::whereSlug($slug)->firstOrFail();
return view('posts.edit')->withPost($post);
}
I am toying with using the ID instead, although I don't think that's where my issue lies. The only difference between the delete function and this new edit function I have is that it uses a string to get the post as opposed to the ID.
The issue I am hitting is when trying to access the edit form for a specific post...
(1/2) UrlGenerationException Missing required parameters for [Route: post-edit] [URI: admin/post/{slug}/edit].
Feel free to offer suggestions of ways to make my code better, I have only recently started using Laravel and this is my first project.
Just in case anyone requests it, here is the 'edit.blade.php' I am passing the $post variable to...
@extends('layouts.panel')
@section('content')
<form class="new-post" method="POST" action="">
{{ csrf_field() }}
<div class="new-post__seperator">
<input type="text" class="new-post__input" id="title" name="title" value="{{ $post->title }}" placeholder="Post Title..." autofocus>
</div>
<div class="new-post__upload"></div>
<div class="new-post__editor">
<textarea id="wysiwyg" value="{{ $post->content }}"></textarea>
</div>
<div class="new-post__checkboxes">
<input type="checkbox" id="publish-checkbox" name="publish-checkbox" class="publish-checkbox" checked>
<label for="publish-checkbox">By checking this box, you will be publishing the post, making it viewable via the home page.</label>
</div>
</form>
@endsection