UPDATE #1:
I fixed my typo:
<form action="{{ route('articles.destroy' , ['article' => $article->id]) }}" method="post">
But now I get this error message:
Illuminate\\Routing\\Exceptions\\UrlGenerationException Missing required parameters for [Route: articles.edit] [URI: admin/articles/{article}/edit]
Here is my web.php
:
Route::prefix('admin')->group(function(){
Route::get('/panel', [PanelController::class, 'index']);
Route::resource('/articles', ArticleController::class);
});
I have a blade which contains a form:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
{{ method_field('delete') }}
{{ csrf_field() }}
<div class="btn-group btn-group-xs">
<a href="{{ route('$articles.edit' . ['id' => $article->id]) }}" class="btn btn-primary">Edit</a>
<button type="submit" class="btn btn-danger">حدف</button>
</div>
</form>
But when I go to this blade, it says:
ErrorException Array to string conversion (View: F:\\xampp\\htdocs\\mywebsite\\resources\\views\\website\\backend\\articles\\index.blade.php)
And it is referring to this line:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
I don't know why I get this error, so if you know why do I get this error, please let me know...
Thanks in advance.
You have a typo:
route('articles.destroy' . ['id' => $article->id])
the .
is for string concatenation. You want ,
, to separate the arguments:
route('articles.destroy', ['id' => $article->id])
You also will need to match the route parameter name with the key you are passing in the array:
route('articles.destroy', ['article' => $article->id])
// admin/articles/{article}
This assumes $article->id
doesn't return null
.
change this:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
to this:
<form action="{{ route('articles.destroy' , ['id' => $article->id]) }}" method="POST">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.