1
votes

When i want to insert data in the database i get this error

MethodNotAllowedHttpException in RouteCollection.php line 219

I'm use resource controller

this is my form

<form action="library" method="POST" enctype="multipart/form-data">
    {!! csrf_field() !!}
        Enter the name of section: <input type="text" name="section_name"> <br>
        Upload an image: <input type="file" name="image"> <br>
        <button type="submit" class="btn btn-default">Create Section</button>
    </form>

and this is my store function

public function store(Request $request)
{

    $section_name = $request->input('section_name');
    $file = $request->file('image');
    $destenationPath = 'iamges';
    $filename = $file->getClientOriginalName();
    $file->move($destenationPath, $filename);
    DB::table('sections')->insert(['section_name' => $section_name, 'image_name' => $filename]);
    return redirect('admin');

}

and this my Route

Route::resource('library', 'Main');
3
Set it in your form like this: action="{{action('Main@store')}}".Ivanka Todorova

3 Answers

1
votes

You are using action="library", so the form is submitted to library. But, here is nothing to deal with library. You need to submit the form to store() method in Mian controller.

Change action="library" to action="{{ action('Main@store') }}" in form starting tag.

0
votes

add this route='library.store' to your form:

<form  method="POST" route="library.store" enctype="multipart/form-data" files="true">

and your rout should be:

Route::resource('library', 'controller_class_name');
0
votes

Change you route to:

Route::resource('library', 'MainController');

Also, check out your controller. It should be placed into app\Http\Controllers directory, named MainController.php and it should include this code:

class MainController extends Controller
{
    ....
    public function store(Request $request)
    ....
}