Этот вопрос закрыт для ответов, так как повторяет вопрос Call to a member function move() on null?
@kaliboba

Call to a member function remove() on null?

Почему выдаёт эту ошибку, что я написал неверно?(Создавал возможность удаления товара из корзины)
web.php
Route::post('/basket/remove/{id}', [BasketController::class,'remove'])
    ->where('id', '[0-9]+')
    ->name('remove');

модель корзины
class Basket extends Model
{
    public function products() {
        return $this->belongsToMany(Product::class)->withPivot('quantity');
    }
    
    public function remove($id) {
        $this->products()->detach($id);
        $this->touch();
    }
}

BasketController(Участок кода, где пишет об ошибке)
private $basket;
public function remove($id) {
        $this->basket->remove($id);
        return redirect()->route('private');
    }

Шаблон
<td>
                    <form action="{{ route('remove', ['id' => $product->id]) }}"
                              method="post">
                            @csrf
                            <button type="submit" class="m-0 p-0 border-0 bg-transparent">
                                <i class="fas fa-trash-alt text-danger">Удалить</i>
                            </button>
                        </form>
                        </td>
                </tr>
  • Вопрос задан
  • 103 просмотра
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы