laravelcpanel

Too few arguments to function Akhaled\CPanelAPI\Modules\AddonDomain::create()


i am try to create addon domain using my akhaled/cpanel-api on my laravel script

i got this error

ArgumentCountError

Too few arguments to function Akhaled\CPanelAPI\Modules\AddonDomain::create(), 3 passed in /home/username/domain.com/app/app/Http/Controllers/AddonDomainController.php on line 26 and exactly 4 expected

here is controller coder

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Akhaled\CPanelAPI\Facades\CPanelAPI;

class AddonDomainController extends Controller
{
    
     public function create()
    {
        
        return view('addondomains.create');
    }
   
   
   
    public function store(Request $request)
    {
        $domain = $request->input('domain');
         $subdomain = $request->input('subdomain');
        $documentRoot = $request->input('document_root');
        $dir = 'public_html/' . $documentRoot;

        CPanelAPI::addonDomain()->create($domain, $subdomain, $dir);

        // Handle the response or redirect as needed
    }
}

and here is route

Route::get('/addon-domain/create', 'AddonDomainController@create');
Route::post('/addon-domain/create', 'AddonDomainController@store')->name('addon-domain.create');

and here is views

<!-- resources/views/addon-domains/create.blade.php -->

@extends('layouts.app')

@section('content')
    <h1>Create Addon Domain</h1>
    
    @if (session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif
    
    <form action="{{ route('addon-domain.create') }}" method="POST">
        @csrf
        
        <div class="form-group">
            <label for="domain">Domain:</label>
            <input type="text" name="domain" id="domain" class="form-control" required>
        </div>
        
        <div class="form-group">
            <label for="subdomain">Subdomain:</label>
            <input type="text" name="subdomain" id="subdomain" class="form-control" required>
        </div>
        
        <div class="form-group">
            <label for="document_root">Document Root:</label>
            <input type="text" name="document_root" id="document_root" class="form-control" required>
        </div>
        
        <button type="submit" class="btn btn-primary">Create</button>
    </form>
@endsection

and here is the package url that i am using now https://packagist.org/packages/akhaled/cpanel-api

i already try to solved it using chatGPT and after try many time chatGPT suggest me take from stackoverflow or mozilla developer


Solution

  • If you look at the source code of the package you'll see that the create method that you are trying to use had 4 arguments up until version 1.1.2.

    public function create(string $domain, string $subdomain, string $dir, string $root_domain)
    

    Since version 1.1.3 the method definition changed to:

    public function create(string $domain, string $subdomain, string $dir = null)
    

    So, you either pass 4 arguments when you use the method, or you update the package to the latest version.