Programmer Notes

lumen installation

Via Composer Create-Project

You may also install Lumen by issuing the Composer create-project command in your terminal:

1
composer create-project --prefer-dist laravel/lumen blog

Serving Your Application

To serve your project locally, you may use the Laravel Homestead virtual machine, Laravel Valet, or the built-in PHP development server:

1
php -S localhost:8000 -t public

Setup Database Connection

root/.env

1
2
3
4
5
6
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Configure App

Uncomment webroot/bootstrap/app.php

1
2
3
4
5
6
$app->withFacades();
$app->withEloquent();

$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);

Create Controller

Create file VisitedController.php in webroot/app/Http/Controllers/ directory

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

namespace App\Http\Controllers;
use App\Visited;
use Illuminate\Http\Request;

class VisitedController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}

//

public function index(){
$data = Visited::all();
return response($data);
}

public function show($id){
return Visited::findOrFail($id);
// $data = Visited::where('id',$id)->get();
// return response ($data);
}

// public function store (Request $request){
// $data = new Todo();
// $data->activity = $request->input('activity');
// $data->description = $request->input('description');
// $data->save();

// return response('Berhasil Tambah Data');
// }

public function update(Request $request, $id){
$data = Visited::where('id',$id)->first();
// $data->status = $request->input('status');
$data->status = 1;
$data->save();

return response('Berhasil Merubah Data');
}

// public function destroy($id){
// $data = Todo::where('id',$id)->first();
// $data->delete();

// return response('Berhasil Menghapus Data');
// }
}


Create New Model

Create file Visited.php in webroot/app/ directory

1
2
3
4
5
6
7
8
9
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class Visited extends Model
{
protected $table = 'visited';
}

Add New Routes

webroot/routes/web.php

1
$router->get('/visited', 'VisitedController@index');