Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

Too few arguments to function 0 passed and exactly 1 expected

I have this blade that pass parameter to the controller:

                @foreach($respondents as $key => $respondent)
                    <tr>
                        <td>
                            {{$key+1}}
                        </td>
                        <td>
                            {{$respondent->employee->employee_code}} - {{$respondent->employee->first_name}} {{$respondent->employee->last_name }}
                        </td>
                        <td>
                            <!--<span data-toggle="tooltip"  data-original-title="Click To View Details">-->
                                 <a class="btn btn-xs btn-info" href="{{ route('appraisal.appraisal_msfs.create', ['id'=>$respondent->id]) }}">
                                    <i class="fas fa-search"></i>
                                    Awaiting Response
                                </a> 
                        </td>
                                           
                </tr>
                @endforeach 

route:

Route::get('/appraisal_msfs/index', 'AppraisalMsfsController@index')->name('appraisal_msfs.index'); 
Route::get('/appraisal_msfs/create/{id}', 'AppraisalMsfsController@create')->name('appraisal_msfs.create'); 
Route::post('/appraisal_msfs/store/{id}', 'AppraisalMsfsController@store')->name('appraisal_msfs.store');  
Route::get('/appraisal_msfs/edit/{id}', 'AppraisalMsfsController@edit')->name('appraisal_msfs.edit'); 
Route::post('/appraisal_msfs/update/{id}', 'AppraisalMsfsController@update')->name('appraisal_msfs.update');  
Route::get('/appraisal_msfs/show/{id}', 'AppraisalMsfsController@show')->name('appraisal_msfs.show'); 

controller

public function create($id)
{
    $userCompany = Auth::user()->company_id;
    $userEmployee = Auth::user()->employee_id;
    $respondent = AppraisalRespondent::where('id', $id)->first();
    $skills = AppraisalSkill::where('company_id', $userCompany)->get();
    $ratings = AppraisalRating::where('company_id', $userCompany)->get();  
    $count_skills = AppraisalSkill::where('company_id', $respondent->company_id)->get()->count();
    return view('appraisal.appraisal_msfs.create')
            ->with('skills', $skills)
            ->with('ratings', $ratings)
            ->with('count_skills', $count_skills)
            ->with('respondent', $respondent);
}  

When I submitted, I got this error:

[2020-10-11 20:52:59] production.ERROR: Too few arguments to function App\Http\Controllers\Appraisal\AppraisalMsfsController::create(), 0 passed and exactly 1 expected {"userId":470,"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Too few arguments to function App\Http\Controllers\Appraisal\AppraisalMsfsController::create(), 0 passed and exactly 1 expected at C:\xampp\htdocs\myapp\app\Http\Controllers\Appraisal\AppraisalMsfsController.php:96)

It highlights:

public function create($id)

When I did route:list, I got this:

|        | GET|HEAD                               | appraisal/appraisal_msfs/create                                                            | appraisal.appraisal_msfs.create                                            | App\Http\Controllers\Appraisal\AppraisalMsfsController@create                                          | web,auth           |
|        | GET|HEAD                               | appraisal/appraisal_msfs/create/{id}                                                       | appraisal.appraisal_msfs.create  

Why is it giving me 2 create. One is with the parameter {id}

How do I resolve it?

Thanks

0 likes
10 replies
Snapey's avatar

what does the page url say when you get this?

MichalOravec's avatar

Do you sometimes read a documentation?

Instead of

{{$key+1}}

use $loop variable

{{ $loop->iteration }}
public function create(Request $request, $id)
{
    $respondent = AppraisalRespondent::find($id);

    $skills = AppraisalSkill::where('company_id', $request->user()->company_id)->get();

    $ratings = AppraisalRating::where('company_id', $request->user()->company_id)->get();

    $count_skills = AppraisalSkill::where('company_id', $respondent->company_id)->count();

    return view('appraisal.appraisal_msfs.create', compact('respondent', 'skills', 'ratings', 'count_skills'));
}

For skills and ratings you can probably use view composers.

Why do you write something like this?

$count_skills = AppraisalSkill::where('company_id', $respondent->company_id)->get()->count();

Can you give me a reason?

noblemfd's avatar

@michaloravec - I used that for this:

                                <td width="25%">
                                <select class="form-control select2bs4" data-placeholder="Select Core Value" tabindex="1" name="appraisal_skill_id[]" required>
                                    <option value="0" selected="true" disabled="true">Select Core Value</option>
                                     @if($skills->count() > 0 )
                                        @foreach($skills as $skill)
                                         <option name="appraisal_skill_id[]"  value="{{$skill->id}}">{{$skill->skill_name}}</option>
                                        @endforeach
                                    @endif                                         
                                </select>                                      
                                </td>                                    
                                <td width="25%">
                                <select class="form-control select2bs4" data-placeholder="Select Rating" tabindex="1" name="appraisal_respondent_rating_id[]" required>
                                    <option value="0" selected="true" disabled="true">Select Rating</option>
                                     @if($ratings->count() > 0 )
                                        @foreach($ratings as $rating)
                                         <option name="appraisal_respondent_rating_id[]"  value="{{$rating->id}}">{{$rating->rating_value}} - {{$rating->rating_description}}</option>
                                        @endforeach
                                    @endif                                         
                                </select>                                      
                                </td>                                    
                                <td width="46%">    
                                  <input type="text" name="comment[]" placeholder="Enter comment here" class="form-control comment" required>
                                </td>
noblemfd's avatar

@snapey This is the page url:

http://localhost:8888/myapp/appraisal/appraisal_msfs/create?id=3

and it shows this screen:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR) Too few arguments to function App\Http\Controllers\Appraisal\AppraisalMsfsController::create(), 0 passed and exactly 1 expected

Then highlights this:

    public function create($id)
   {
MichalOravec's avatar

Where do you have defined that route appraisal.appraisal_msfs.create? You said that you see it twice there. Why?

And I asked for something else.

By the ay you really want to have appraisal_msfs in url? I mean _.

noblemfd's avatar

@michaloravec - That's what gives me concern. This is what I used and didn't use resource:

Route::get('/appraisal_msfs/index', 'AppraisalMsfsController@index')->name('appraisal_msfs.index'); 
Route::get('/appraisal_msfs/create/{id}', 'AppraisalMsfsController@create')->name('appraisal_msfs.create'); 
Route::post('/appraisal_msfs/store/{id}', 'AppraisalMsfsController@store')->name('appraisal_msfs.store');  
Route::get('/appraisal_msfs/edit/{id}', 'AppraisalMsfsController@edit')->name('appraisal_msfs.edit'); 
Route::post('/appraisal_msfs/update/{id}', 'AppraisalMsfsController@update')->name('appraisal_msfs.update');  
Route::get('/appraisal_msfs/show/{id}', 'AppraisalMsfsController@show')->name('appraisal_msfs.show'); 

I don't know how I got that.

MichalOravec's avatar

Before asking another question on this forum, please read at least 10 times whole documentation of Laravel. Watch some videos on Laracasts etc. It will help to you so much.

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

have you cached routes? Always use php artisan route:clear in development.

Change your view;

<a class="btn btn-xs btn-info" href="{{ route('appraisal.appraisal_msfs.create', $respondent->id) }}">

Please or to participate in this conversation.