From 590231337d99e49fb0945f665c3f112ed0084e6b Mon Sep 17 00:00:00 2001 From: icalF <laser.survivor@gmail.com> Date: Sun, 3 Apr 2016 12:22:46 +0700 Subject: [PATCH] rest model controller --- app/Http/Controllers/ScheduleController.php | 50 ++++++++++++++++++ app/Http/Controllers/TpsController.php | 51 +++++++++++++++++++ app/Http/Controllers/UserController.php | 51 +++++++++++++++++++ app/Http/Middleware/Authenticate.php | 2 +- app/Http/routes.php | 8 ++- app/Tps.php | 5 ++ .../2016_04_02_171120_create_tps_table.php | 2 +- 7 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/ScheduleController.php create mode 100644 app/Http/Controllers/TpsController.php create mode 100644 app/Http/Controllers/UserController.php diff --git a/app/Http/Controllers/ScheduleController.php b/app/Http/Controllers/ScheduleController.php new file mode 100644 index 0000000..f21761e --- /dev/null +++ b/app/Http/Controllers/ScheduleController.php @@ -0,0 +1,50 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use App\Schedule; +use App\Http\Requests; + +class ScheduleController extends Controller +{ + public function index() + { + return Schedule::all(); + } + + public function store() + { + $sched = Schedule::create(Input::all()); + return $sched; + } + + public function create() + { + // view create doang + } + + public function show($id) + { + // viewnya pake get + return Schedule::find($id); + } + + public function edit($id) + { + // viewnya pake form edit + return Schedule::find($id); + } + + public function update($id) + { + $sched = Schedule::find($id); + $sched->update($input); + return $sched; + } + + public function destroy($id) + { + Schedule::find($id)->delete(); + return Schedule::all(); + } diff --git a/app/Http/Controllers/TpsController.php b/app/Http/Controllers/TpsController.php new file mode 100644 index 0000000..436e9bc --- /dev/null +++ b/app/Http/Controllers/TpsController.php @@ -0,0 +1,51 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use App\Tps; +use App\Http\Requests; + +class TpsController extends Controller +{ + public function index() + { + return Tps::all(); + } + + public function store() + { + $tps = Tps::create(Input::all()); + return $tps; + } + + public function create() + { + // view create doang + } + + public function show($id) + { + // viewnya pake get + return Tps::find($id); + } + + public function edit($id) + { + // viewnya pake form edit + return Tps::find($id); + } + + public function update($id) + { + $tps = Tps::find($id); + $tps->update($input); + return $tps; + } + + public function destroy($id) + { + Tps::find($id)->delete(); + return Tps::all(); + } +} diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..fe4904f --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,51 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; +use App\User; +use App\Http\Requests; + +class UserController extends Controller +{ + public function index() + { + return User::all(); + } + + public function store() + { + $user = User::create(Input::all()); + return $user; + } + + public function create() + { + // view create doang + } + + public function show($id) + { + // viewnya pake get + return User::find($id); + } + + public function edit($id) + { + // viewnya pake form edit + return User::find($id); + } + + public function update($id) + { + $user = User::find($id); + $user->update($input); + return $user; + } + + public function destroy($id) + { + User::find($id)->delete(); + return User::all(); + } +} diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index a08e42a..c09d7cd 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -17,7 +17,7 @@ class Authenticate */ public function handle($request, Closure $next, $guard = null) { - dd(Auth::guard($guard)); + // dd($request); if (Auth::guard($guard)->guest()) { if ($request->ajax() || $request->wantsJson()) { return response('Unauthorized.', 403); diff --git a/app/Http/routes.php b/app/Http/routes.php index 6ef66fb..d5ef42b 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -11,8 +11,12 @@ | */ -Route::group(['middleware' => 'web'], function () { +Route::group(['middleware' => ['web', ]], function () { Route::auth(); - + Route::get('/', 'HomeController@index'); // homnya kan cm 1 Route::get('/home', 'HomeController@index'); }); + +Route::resource('user', 'UserController'); +Route::resource('tps', 'TpsController'); +Route::resource('schedule', 'ScheduleController'); diff --git a/app/Tps.php b/app/Tps.php index 6d8825e..5d3343c 100644 --- a/app/Tps.php +++ b/app/Tps.php @@ -10,4 +10,9 @@ class Tps extends Model { return $this->hasMany('App\Schedule', 'id_tps'); } + + public function manager() + { + return $this->hasOne('App\User', 'id_manager'); + } } diff --git a/database/migrations/2016_04_02_171120_create_tps_table.php b/database/migrations/2016_04_02_171120_create_tps_table.php index 7306c9c..f36ce53 100644 --- a/database/migrations/2016_04_02_171120_create_tps_table.php +++ b/database/migrations/2016_04_02_171120_create_tps_table.php @@ -17,7 +17,7 @@ class CreateTpsTable extends Migration $table->increments('id'); $table->integer('capacity_now'); $table->integer('capacity_full'); - $table->integer('manager_id')->unsigned(); + $table->integer('id_manager')->unsigned(); $table->timestamps(); }); } -- GitLab