Laravel Project (MVC) – Beginning

create database lms_laravel_db;

CREATE TABLE user_account(
id INT PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(25) NOT NULL,
email_id VARCHAR(200) NOT NULL,
PASSWORD VARCHAR(50) NOT NULL
);

download composer and install
https://getcomposer.org/download/

download laravel
C:\Users\EP>composer global require “laravel/installer”

create project
C:\Users\EP>composer create-project –prefer-dist laravel/laravel blog
Note:–(double hyphen) before prefer
C:\Users\EP\blog\.env, edit the following
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=lms_laravel_db
DB_USERNAME=root
DB_PASSWORD=password

C:\Users\EP\blog\config\database.php, edit mysql
Note:/*comment all other database */

C:\Users\EP>cd blog

C:\Users\EP\blog>php artisan serve
Laravel development server started:

In chrome,
http://127.0.0.1:8000/

C:\Users\EP\blog>php artisan make:model UserAccount
Model created successfully.
In C:\Users\EP\blog\app\UserAccount, edit the model

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class UserAccount extends Model
{
    protected $table = 'user_account';
    protected $primaryKey = 'id';
}

C:\Users\EP\blog>php artisan make:controller UserAccountController –resource
Controller created successfully.
Note:–(double hyphen) before resource

C:\Users\EP\blog\app\Http\Controllers\UserAccountController, edit the controller

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
class UserAccountController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $list = DB::table('user_account')
		->select ('id', 'name', 'email_id', 'password')
		->get();
    	return response()->json($list);
    }
}

C:\Users\EP\blog\routes\api.php, edit the api.php

Route::resource(‘users’, ‘UserAccountController’);

http://localhost:8000/api/users

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s