在laravel 5.5中,数据不会保存到数据库中

时间:2018-05-12 22:27:18

标签: php mysql laravel

当我填写并提交表单时,数据不会持久存储到我的Mysql数据库中。

你知道我做错了什么吗?

我的地址控制器如下所示:

App/Address
......




public function store(Request $request)
            {
                $this->validate($request,[
                    'addressline'=>'required',
                    'city'=>'required',
                    'state'=>'required',
                    'zip'=>'required|integer',
                    'contry'=>'required',
                    'phone'=>'required|integer',

                ]);

                Auth::user()->address()->create($request->all());
                Address::create($request->all());
                return redirect()->back();

            }

路线:

 Route::post('shipping-info','CheckoutController@store')->name('checkout.shipping');

地址模型:

class Address extends Model
{
    protected $fillable=['addressline','city','state','zip','phone','country'];
}

刀锋视图:

 @extends('layouts.main')

@section('content')
    <br>
<div class="row">
    <div class="small-6 small-centered columns">
        <h3>Shipping Info</h3>

              {!! Form::open(['route' => 'checkout.shipping', 'method' => 'POST', 'files' => true, 'data-parsley-validate'=>'']) !!}


..........

{{ Form::submit('Proceed to Payment', array('class' => 'button success')) }}
{!! Form::close() !!}

1 个答案:

答案 0 :(得分:0)

如果您打算调用AddressController的store方法,那么错误就在您的路径中。你应该改变

data.table

Route::post('shipping-info','CheckoutController@store')->name('checkout.shipping');

另外,我不确定你为什么需要这个

Route::post('shipping-info','AddressController@store');