4

I want to use a argument in a create action, but when I try to access the action:

Missing argument 1 for App\Http\Controllers\AdsDiagController::create()

Here is the create action:

public function create($id){
    $record = TestRecord::findOrFail($id);
    return view("adsdiag.create", ["record" => $record]);
}

Here is the link to the action:

<a href="{!! action('AdsDiagController@create', $record->id ) !!}">Create</a>

And the route:

Route::resource('adsdiag', 'AdsDiagController');

I'm newbie in laravel, and I'm really confused with routes. I appreciate any help.

2 Answers 2

3

To solve your problem you should use in your route.php

Route::get('adsdiag/{id}/',AdsDiagController@create);

Reason

When you call Route::resource('adsdiag', 'AdsDiagController') it generates these routes

Route::get('adsdiag','AdsDiagController@index');
Route::post('adsdiag','AdsDiagController@store');
Route::get('adsdiag/create','AdsDiagController@create'); // you can see that create method doesn't have any arguments here.
Route::get('adsdiag/show/{id}','AdsDiagController@show');
Route::post('adsdiag/update','AdsDiagController@update');
Route::get('adsdiag/edit/{id}','AdsDiagController@edit');
Route::delete('adsdiag/destroy/{id}','AdsDiagController@destroy');

Since Route::get('adsdiag/{id}/',AdsDiagController@create); is not generated by Resourcce so you need to include in your route explicitly.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to pass the arguments to the action() helper method in an array, even if it's just one argument:

action('AdsDiagController@create', [$record->id])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.