Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

Code, please

Last updated 2 years ago.
0
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";

});

Last updated 2 years ago.
0

May be the blank url in the Route::post() is your problem

Last updated 2 years ago.
0

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>
Last updated 2 years ago.
0

Your Route::post() has blank parameter

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Is your User::fillable property is set.

http://laravel.com/docs/eloquent#mass-assignment

Last updated 2 years ago.
0

Thanks lots bomberman1990

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.