Laravel can't Delete data, it can enter on destroy() function but it parameter return null

So i’m try to delete data on laravel using resource route. but the data remain and still return the function. Im also try to delete the Greens from destroy() parameter, it make $greens containing ‘id’. but still, i want to keep destroy() parameter to be (Greens $greens), not just ($greens)

Controller :

    public function destroy(Greens $greens)
        return redirect('/greens');

Form :

<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">


        @foreach ($data as $d)
                <form action="/greens/{{$d['id']}}" method="POST">



Model :


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Greens extends Model
    use HasFactory;
    protected $primaryKey = 'id';



use App\Http\Controllers\GreensController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
Route::resource('/greens', GreensController::class);

i try to var_dump $greens->id but the result is null

>Solution :

When you use Laravel Route Resource, there’s a format you should follow, refer to this link:

I can see here in your destroy function $greens is in plural, you should use the singlular form $green:

public function destroy(Greens $green)
    return redirect('/greens');

Leave a Reply