Showing posts with label Laravel. Show all posts
Showing posts with label Laravel. Show all posts

How to insert records in Laravel using database

agyanadda

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


Laravel First Program

agyanadda

How to create Modal . controller and index page in Laravel

================================================= Model= college.php ================================================= <!--php namespace App; use Illuminate\Database\Eloquent\Model; class College extends Model { public $name='SMSG COLLEGE'; public $pin=824211; } ================================================== Controller= CollegeController.php ================================================== namespace App\Http\Controllers; use Illuminate\Http\Request; use App\College; class CollegeController extends Controller { public function index(){ $collg= new College(); $nm = $collg--->name; $pn = $collg->pin; return view('College.index',compact('nm','pn')); } } ===================================================== Views= index.blade.php ===================================================== <!--DOCTYPE html--> <html> <head> <title>LaravelAPP</title> </head> <body> Welcome to laravel <br> {{$nm}} {{$pn}} </body> </html> ====================================================== Routes= web.php ====================================================== Auth::routes(); Route:: get('/index','CollegeController@index');