2016-10-05 4 views
1

コードのどこかにバグがあり、それを見つけることができないようです。そのDBに格納するシンプルなフォーム。Laravelデータベースには投稿していません

アプリはlaravel 5.2を使用しています。データを収集するだけで済みます。送信ボタンがフォームに何も表示されないとき!

ルート

Route::resource('/form' , 'PagesController'); 

コントローラは、インデスに必要作成して保存、すべてのアプリが行う必要があるのthats。

<?php 

namespace App\Http\Controllers; 

use Request; 
use App\Http\Requests; 
use Data; 
use App\Http\Requests\DataRequest; 
use Carbon\Carbon; 

class PagesController extends Controller 
{ 
    //Display Index 
    public function index() 
    { 
     return view ('welcome'); 
    } 

    public function create() 
    { 
     return view ('create'); 
    } 

    //Store Articles from form 
    public function store(DataRequest $request) 
    { 
     Data::create($request->all()); 
     return redirect('create')->with('message' , 'Form submitted'); 
    } 


} 

モデルは、タイムスタンプ

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 
use App\Http\Requests\DataRequest; 
use Carbon\Carbon; 

class Data extends Model 
{ 
    protected $fillable = [ 
     'name', 
     'email', 
     'phone', 
     'company', 
     'addcomments', 
     'published_at', 
    ]; 

    protected $dates = ['published_at']; 

    //Get all published articles by date 
    public function scopePublished($query) 
    { 
     $query->where('published_at' , '<=' , Carbon::now()); 
    } 
    //Get all unpublished or future articles 
    public function scopeUnpublished($query) 
    { 
     $query->where('published_at' , '>=' , Carbon::now()); 
    } 
    // Set form to publish articles with a time and date in the Published_at field 
    public function setPublishedAtAttribute($date) 
    { 
     $this->attributes['published_at'] = Carbon::createFromFormat('Y-m-d' , $date); 
    } 
} 

{!! Form::open(['url' => 'form']) !!} 
      <div class="form-group"> 
       {!! Form::label('name' , 'Name:') !!} 
       {!! Form::text('name', null , ['class' => 'form-control']) !!} 
      </div> 
      <div class="form-group"> 
       {!! Form::label('email' , 'EMail:') !!} 
       {!! Form::text('email', null , ['class' => 'form-control']) !!} 
      </div> 
      <div class="form-group"> 
       {!! Form::label('phone' , 'Phone Number:') !!} 
       {!! Form::text('phone', null , ['class' => 'form-control']) !!} 
      </div> 
      <div class="form-group"> 
       {!! Form::label('company' , 'Company:') !!} 
       {!! Form::text('company', null , ['class' => 'form-control']) !!} 
      </div> 
      <div class="form-group"> 
       {!! Form::label('addcomments' , 'Additional Comments:') !!} 
       {!! Form::textarea('addcomments', null , ['class' => 'form-control']) !!} 
      </div> 
      <div class="form-group"> 
       {!! Form::submit('Submit Now', ['class' => 'btn btn-primary form-control']) !!} 
      </div> 
      {!! Form::close() !!} 
+0

をソート微調整では、すべてのページの更新を場合、またはあなたがsubmiitを押したときに、それはsomplyのnothinをするのでしょうか? /をURLに入れてみてください! Form :: open(['url' => '/ form'])!}。 – Carlos

+0

$ requestをlaravelログにログアウトすると、期待しているすべてのデータが得られますか? –

+0

このコードはまったく機能しますか?あなたはデータのために間違った名前空間を使用しています –

答えて

0

だから問題は、コメントで言及したものを形

利用データを保存するために、単純な保護フィールドリストとカーボンを使用しています;

~

使用App \ DATA;

といくつかの小さなフロントエンドの混合物が

はすべて

関連する問題