Laravel 5.4表单post和save()不起作用

时间:2017-08-14 23:07:12

标签: forms laravel post eloquent save

我在将数据提交到数据库时遇到问题。数据库工作正常,因为我可以将数据放入其中并显示数据。我怀疑帖子表格有问题,因为我没有得到任何错误,就像帖子根本没有达到控制器一样。以下是文件:

观点:

function newQuote () {
    var self = this;

    $.ajax(
        {
        dataType : "jsonp",
        jsonp : "jsonp",
        url : "https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en",
        error : function(data) {
                alert("Error - 2");
        },
        success : function(response){
            console.log(response);
            self.quoteAuthor = response.quoteAuthor;
            self.quoteLink = response.quoteLink;
            self.quoteText = response.quoteText;
            console.log(self);
        }
    });
}   

function ModelView () {
    var self = this;

    self.quotesArray = ko.observableArray([
        {quoteAuthor: "Neil Alden Armstrong", 
        quoteLink: "https://en.wikiquote.org/wiki/Neil_Armstrong", 
        quoteText: "That's one small step for man, one giant leap for mankind."},

        {quoteAuthor: "Mark Twain (Samuel Langhorne Clemens)", 
        quoteLink: "https://en.wikiquote.org/wiki/Mark_Twain", 
        quoteText: "If you tell the truth you don't have to remember anything."}
    ]);

    self.addQuote = function () {
        self.quotesArray.push(new newQuote());
    };
}

ko.applyBindings(new ModelView());

路线:

@extends('layouts.master')

@section('title') Homepage @endsection

@section('content')
    <h1>Homepage:</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad architecto aut consectetur debitis deleniti dolore ducimus, eaque ex, harum itaque laudantium nobis odit, officiis quae rem saepe sunt unde veritatis!</p>




    <div style=" width: 100%; text-align: center; display: inline-block;">

        @foreach($actions as $action)
            <a href="{{route('niceaction',['action'=>lcfirst($action->name)])}}"><h3>{{ $action->name }}</h3></a>
            <br>
        @endforeach

    </div>

    <div>
    <form action=" {{ route ('add_action') }}" method ="post">
        <label for="name">Enter name:</label>
        <input type="text" name="name" id="name"/>
        <label for="niceness">Niceness level:</label>
        <input type="text" name="niceness" id="niceness"/>
        <button type="submit" >Do a nice action!</button>
       <input type="hidden" value="{{csrf_token()}}" name="_token"/>
    </form>


    </div>
@endsection

和控制器:

<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group(['middleware' => ['web']], function() {

    Route::get('/', [
        'uses' => 'NiceActionController@getHome',
        'as' => 'home'
    ]);


    Route::group(['prefix'=> 'do'], function(){

        Route::get('/{action}/{name?}', [
            'uses' => 'NiceActionController@getNiceAction',
            'as' => 'niceaction'
        ]);



        Route::post('/add_action', [
            'uses' => 'NiceActionController@postInsertNiceAction',
            'as' => 'add_action'
        ]);

    });

});

0 个答案:

没有答案