0

I installed laravelcollective and am trying to run the following code

{!! Form::open(['action' => 'ProductController@store','method' => 'POST']) !!}
    <div class="form-group">
        {{Form::label('title','Title')}}
        {{Form::text('title',['class' => 'form-control', 'placeholder' => 'Title'])}}
    </div>
{!! Form::close() !!}

I get this error

App\Http\Controllers\ProductController@store not defined. (View: /Applications/MAMP/htdocs/lsapp/resources/views/product/create.blade.php)

When I run php artisan route:list I see:

    |        | GET|HEAD  | api/user               |                  | Closure              | api,auth:api |
|        | POST      | events                 | events.store     | App\Http\Controllers\eventcontroller@store              | web          |
|        | GET|HEAD  | events                 | events.index     | App\Http\Controllers\eventcontroller@index              | web          |
|        | GET|HEAD  | events/create          | events.create    | App\Http\Controllers\eventcontroller@create              | web          |
|        | PUT|PATCH | events/{event}         | events.update    | App\Http\Controllers\eventcontroller@update              | web          |
|        | GET|HEAD  | events/{event}         | events.show      | App\Http\Controllers\eventcontroller@show              | web          |
|        | DELETE    | events/{event}         | events.destroy   | App\Http\Controllers\eventcontroller@destroy              | web          |
|        | GET|HEAD  | events/{event}/edit    | events.edit      | App\Http\Controllers\eventcontroller@edit              | web          |
|        | GET|HEAD  | home                   | home             | App\Http\Controllers\HomeController@index              | web,auth     |
|        | POST      | login                  |                  | App\Http\Controllers\Auth\LoginController@login              | web,guest    |
|        | GET|HEAD  | login                  | login            | App\Http\Controllers\Auth\LoginController@showLoginForm              | web,guest    |
|        | POST      | logout                 | logout           | App\Http\Controllers\Auth\LoginController@logout              | web          |
|        | POST      | password/email         | password.email   | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD  | password/reset         | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST      | password/reset         |                  | App\Http\Controllers\Auth\ResetPasswordController@reset              | web,guest    |
|        | GET|HEAD  | password/reset/{token} | password.reset   | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | POST      | register               |                  | App\Http\Controllers\Auth\RegisterController@register              | web,guest    |
|        | GET|HEAD  | register               | register         | App\Http\Controllers\Auth\RegisterController@showRegistra
5
  • 1
    Have you created ProductController and in that store method ? Commented Oct 30, 2017 at 9:05
  • 2
    Can you post your routes file too Commented Oct 30, 2017 at 9:08
  • @Option done I added routes Commented Nov 1, 2017 at 6:00
  • @Pratik yes i have added routes Commented Nov 1, 2017 at 6:00
  • @joem where is the ProductController related routes Commented Nov 2, 2017 at 5:38

3 Answers 3

3

for the best practice and to have maintained code I wish to follow my advice :

1) go to routes/web.php and add name to your ProductController@store method like this :

Route::post('','ProductController@store')->name('products.store');

2) go to you create.blade.php file and change it like this :

{!! Form::open(array( 'route'=>'products.store')) !!} 
    <div class="form-group">    
    {{Form::label('title','Title')}}  
    {{Form::text('title',['class' => 'form-control', 'placeholder' => 'Title'])}} 
    </div>
Sign up to request clarification or add additional context in comments.

3 Comments

I'm following this tutorial: He did not use a route? youtu.be/-QapNzUE4V0?t=4m58s????
to use both of route or action is the same thing
I have added route list above
0

When you use the Laravel Collective form with action, you do not declare the method as the second parameter, that's only if you declare a url, you use that as route parameters, usually to add in an ID if one is needed in the url. First, try and remove the 'method' => 'POST' section and see if that works.

2 Comments

I'm following this tutorial: He did not use a route? youtu.be/-QapNzUE4V0?t=4m58s ??
You can check the documentation for Laravel Collective here to show that you don't need it. laravelcollective.com/docs/master/html
0

Have you created a resource controller or a single route in your routes/web.php file?

You have couple of options here:

For your Form::open, you can use either Action, Route or URL

Action:

   {!! Form::open(['action' => 'ProductController@store']) !!}
    // By default, a POST method will be assumed 
        <div class="form-group">
            {{Form::label('title','Title')}}
            {{Form::text('title',['class' => 'form-control', 'placeholder' => 'Title'])}}
        </div>
    // If you use the Form::open method with POST, PUT or DELETE the CSRF token will be added to your forms as a hidden field automatically.
    {!! Form::close() !!}

Route:

First name your route in your routes/web.php file:

Route::post('/productURL', 'ProductController@store')->name('productRouteName');

Then open the form:

{!! Form::open(['route' => 'productRouteName'] !!}

URL:

Just call the url from the route you created above..

{!! Form::open(['url' => 'productURL'] !!}

7 Comments

I'm following this tutorial: He did not use a route? youtu.be/-QapNzUE4V0?t=4m58s
He has created a resource controller, most likely by using "php artisan make:controller ProductController --resource" in a terminal. You can check if you have this by viewing your routes by using "php artisan route:list".
So you have not created your Product route yet? If you havent already, run the make:controller command in my comment above, and then add "Route::resource('product','ProductController');" to your routes/web.php file.
Also, I see you have created an EventController already. Whilst you are learning, its a good idea to follow the coding conventions and use CamelCase to name your controllers.
Hello, I have added that, It seems that just @update isnt working ? all the other routes in the controller are
|

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.