Search code examples
laravellaravel-5laravel-routing

Too few arguments to function App\Http\Controllers\CategoryController::destroy(), 0 passed and exactly 1 expected


i can not delete it by id

and i have some code here for Model too

class Category extends Model
{

    // Table Name
    protected $table = 'categories';
    // Primary Key

    public $primaryKey = 'id';
    // TimeStamps
    public $timestamps = true;

    protected $fillable= ['name','icon'];


    public function getAllCategory(){
        return DB::table(categories)->get();

    }

    public function createCategory($name,$icon){
            $category= $this->create([
                'name' => $name,
                'icon' => $icon,
            ]);
            return $category;
    }
}

//here is a function in controller:

public function destroy($id)
{
    $category = Category::findOrFail($id);
    $category->delele();
    return redirect('/admin.category');

}

Solution

  • I think the problem is in your routes/web.php file You have to pass one argument to destroy method eg:

    Route::get('delete_category/{id}', 'CategoryController@destroy');
    

    And your invoking URL will look like http://127.0.0.1:8000/delete_category/1 Here 1 will take as the value of id variable