Laravel 8: 视图中的数组到字符串的转换
Laravel 8: Array to string conversion on view
更新#1:
我修正了我的错别字:
<form action="{{ route('articles.destroy' , ['article' => $article->id]) }}" method="post">
但现在我收到此错误消息:
Illuminate\Routing\Exceptions\UrlGenerationException Missing required
parameters for [Route: articles.edit] [URI:
admin/articles/{article}/edit]
这是我的 web.php
:
Route::prefix('admin')->group(function(){
Route::get('/panel', [PanelController::class, 'index']);
Route::resource('/articles', ArticleController::class);
});
我有一个 blade,其中包含一个表单:
<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>
但是当我转到这个 blade 时,它说:
ErrorException
Array to string conversion (View: F:\xampp\htdocs\mywebsite\resources\views\website\backend\articles\index.blade.php)
它指的是这一行:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
我不知道为什么会收到此错误,所以如果您知道为什么会收到此错误,请告诉我...
提前致谢。
改变这个:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
对此:
<form action="{{ route('articles.destroy' , ['id' => $article->id]) }}" method="POST">
你打错了:
route('articles.destroy' . ['id' => $article->id])
.
用于字符串连接。您希望 ,
分隔参数:
route('articles.destroy', ['id' => $article->id])
您还需要将路由参数名称与您在数组中传递的键相匹配:
route('articles.destroy', ['article' => $article->id])
// admin/articles/{article}
这假设 $article->id
不 return null
。
更新#1:
我修正了我的错别字:
<form action="{{ route('articles.destroy' , ['article' => $article->id]) }}" method="post">
但现在我收到此错误消息:
Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameters for [Route: articles.edit] [URI: admin/articles/{article}/edit]
这是我的 web.php
:
Route::prefix('admin')->group(function(){
Route::get('/panel', [PanelController::class, 'index']);
Route::resource('/articles', ArticleController::class);
});
我有一个 blade,其中包含一个表单:
<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>
但是当我转到这个 blade 时,它说:
ErrorException Array to string conversion (View: F:\xampp\htdocs\mywebsite\resources\views\website\backend\articles\index.blade.php)
它指的是这一行:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
我不知道为什么会收到此错误,所以如果您知道为什么会收到此错误,请告诉我...
提前致谢。
改变这个:
<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">
对此:
<form action="{{ route('articles.destroy' , ['id' => $article->id]) }}" method="POST">
你打错了:
route('articles.destroy' . ['id' => $article->id])
.
用于字符串连接。您希望 ,
分隔参数:
route('articles.destroy', ['id' => $article->id])
您还需要将路由参数名称与您在数组中传递的键相匹配:
route('articles.destroy', ['article' => $article->id])
// admin/articles/{article}
这假设 $article->id
不 return null
。