Add records in DB in laravel
1. Create
model: php artisan make:model employe –m
Model
created: name: employe [
apps/provider ]
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class employe extends Model
{
//
}
2 . Created migration: name [
2018_03_21_045529_create_employes_table]
public function up()
{
Schema::create('employes', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('mobile');
$table->string('address');
$table->timestamps();
});
}
3. Execute command : php artisan migrate;
Note: if there is error while
migrate then follow given following steps;
GO TO: App\providers and open it= [ AppServiceprovider.php] and add given code
use Illuminate\Support\Facades\Schema; // add it
public function boot()
{
Schema::defaultStringLength(191);
// add it
}
Now, execute your command: php
artisan migrate; and php artisan migrate:refresh;
Now created: controller : App\http\Controller [ php artisan make:controller
<controller-name>
Example : php artisan make:conntroller
EmployeeController -r
Add: use App\employe; [ where employee = model name]
public function create()
{
$emp = new employe;
$emp->name='Aryan';
$emp->mobile='78585';
$emp->address='Delhi';
$emp->save();
// by default save() method
}
Now: Got to Route folder: [web.php]
Route::get('/save', 'EmployeeController@create');
Route::get(‘/localhost
url [name],’Controller name @ method name’)
Save Record from textbox;
Create : registration.blade.ph