删除路由未获取任何数据Laravel 6.X

问题描述 投票:0回答:1

我尝试更改路线,并在action属性中使用特定名称和几项内容,但是当我在删除路线上使用表格进行删除和dd()函数时,数据不会出现here is what the dd shows me, no info at all

我的路线:

Route::get('/home/Collections', 'CollectionController@index')->name('collection.index');
Route::get('/home/Collections/{Collection}', 'CollectionController@show')->name('collection.show');
Route::get('/home/Collections/{Collection}/edit', 'CollectionController@edit')->name('collection.edit');
Route::put('/home/Collections/{Collection}', 'CollectionController@update')->name('collection.update');
Route::get('/home/Collections/crear', 'CollectionController@create')->name('collection.create');
Route::delete('/home/Collections/{Collection}', 'CollectionController@destroy')->name('collection.destroy');
Route::post('/home/Collections', 'CollectionController@store')->name('collection.store');

我的控制器:

public function destroy(Collection $collection)
{
    $collection->delete();
    return redirect('/home'.'/Collections');
}

和我的表格:

@foreach ($collections as $collection)
<div id="{{$collection->id}}">
    <img/>
    <p>{{$collection->name}}</p>
    <p>{{$collection->description}}</p>
    <form action="/home/Collections/{{$collection->id}}" method="POST">
        @csrf
        @method('DELETE')
        <input type="submit" value="ELIMINAR" class = "btn btn-outline-danger mt-2">
    </form>
</div>
@endforeach

我的收藏模型:

class Collection extends Model implements Searchable

{受保护的$ fillable = ['id','name','description','user_id','category_id','certificate_id','img_id'];

public function items()
{
    return $this->hasMany(Item::class);
}
public function certificate()
{
    return $this->hasOne(Certificate::class);
}
public function image()
{
    return $this->hasOne(Image::class);
}
public function category()
{
    return $this->belongsTo(Category::class);
}
public function user()
{
    return $this->belongsTo(User::class);
}
public function getSearchResult(): SearchResult
{
    $url = route('collection.show', $this->id);

    return new SearchResult(
        $this,
        $this->name,
        $url
     );

}

}

php laravel controller routes http-delete
1个回答
-3
投票

您不只是发送一个集合,您必须先找到该集合然后找到它,然后销毁,将控制器更新为

public function destroy($id)
{
  $collection = Collection::destroy($id);

  return redirect('/home'.'/Collections');
}
© www.soinside.com 2019 - 2024. All rights reserved.