php - Laravel 8: Array to string conversion on view

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.

Answer

Solution:

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.

Answer

Solution:

change this:

<form action="{{ route('articles.destroy' . ['id' => $article->id]) }}" method="POST">

to this:

<form action="{{ route('articles.destroy' , ['id' => $article->id]) }}" method="POST">

Source