public function up()
{
//
Schema::create('users', function($t) {
$t->increments('id');
$t->string('name', 80);
$t->integer('number');
$t->string('location', 80);
$t->integer('phone');
$t->timestamps();
});
DB::table('users')->insert(array(
'name' => Input::get('name'),
'number' => Input::get('number'),
'location' => Input::get('location'),
'phone'=>Input::get('phone'),
));
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::drop('users');
}
routes.php Route::get('', function() { return View::make('new');
});
Route::post('', function() { $newStudent=array( 'name'=> Input::get('name'), 'number'=> Input::get('number'), 'location'=> Input::get('location'), 'phone'=>Input::get('phone')
);
$rules = array( # validation code 'name' => 'Required|Min:3|Max:80|Alpha', 'number'=> 'Required|Between:3,64', 'location'=> 'Required|Min:3|Max:80|Alpha', 'phone'=>'Required|Between:3,64', ); $validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('')
->with_errors($validation)
->with_input();
}
$newStudent = new User($newStudent); $newStudent->save(); echo"inserted";
});
May be the blank url in the Route::post()
is your problem
form is Exists on the page new.blade.php
<html> <body> <h2>new</h2> <form action="" method="POST" onsubmit="return confirm('Are you sure you want to submit?')"> <table border='1'>
<thead>
<tr>
<td>name</td>
<td>number</td>
<td>location</td>
<td>phone</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="name" ></td>
<td><input type="text" name="number" ></td>
<td><input type="text" name="location" ></td>
<td><input type="text" name="phone" ></td>
</tr>
</tbody>
</table>
<!-- submit button -->
<p>{{Form::submit()}}</p>
{{ Form::close() }}
</body> </html>Your Route::post()
has blank parameter
i am use var_dump(Input::all()); At the end of Route::post I printed all the data on the form but not insert to table
Is your User::fillable property is set.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community