Saving twice to database

Posted 2 years ago by Shiva

I hope someone can please look at my code and tell me what I've done wrong. For some reason when I create a new database item it gets saved twice instead of once.

My create.blade.php

{{ Form::open(array('route' => '', 'class' => 'add-form')) }}
                {{ csrf_field() }}
                <div class="form">

                    <div class="menu_input">
                            {{ Form::label('menu_id', 'Menu') }}
                            {{ Form::select('menu_id', $menu_options, '', array("class" => "form-control")) }}
                    <div class="title_input">
                            {{ Form::label('title', 'Title') }}
                            {{ Form::text('title','', array('id' => 'title', 'class' => 'form-control')) }}

                    <div class="content_input">
                            {{ Form::label('content', 'Content') }}
                            {{ Form::textarea('content','', array('id' => 'content', "class" => "form-control")) }}

                    <div class="image_uploader">
                        <div id="fileuploader" class="image_upload">Upload</div>
                            var uploadObj = $("#fileuploader").uploadFile(settings);
                        {{ Form::hidden('image', '', array('id' => 'img-add', 'class' => 'img-hidden')) }}

                    <div class="submit_button">
                        {{ Form::submit('Submit', array("class" => "btn btn-info submit", "role" => "button")) }}
            {{ Form::close() }}

my store method in my ContentController.php

public function store(Request $request)
        //Gets all the input in the fields in the form
        $input = Input::all();
        //Checks the input fields against the validation rules in the Content model
        $validation = Validator::make($input, Content::$rules);

        //If the validation fails the a message will pop up saying that there was validation errors
            return redirect()->route('admin.content.create')
                ->with('message', 'There were validation errors');

        //If the validation passes then it gets saved to the database

            $content = new Content();

            //Gets the menu_id
            $menuId = (array) array_get($input, 'menu_id');
            //Saves the input to the database
            //Syncs the menu function in the Content model to save the menu ID in content_menu

            $content = Content::all();

            return view('content::admin.index', compact('content'));

Please sign in or create an account to participate in this conversation.