From 4548b12cdd799a081a58117232b9b90a1b14cdea Mon Sep 17 00:00:00 2001 From: Goros6 Date: Thu, 20 Nov 2014 07:51:35 +0500 Subject: [PATCH] =?UTF-8?q?#1=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=20?= =?UTF-8?q?=D0=B6=D0=B4=D1=8F=20PurchaseStatuse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config/examples/database.php | 7 +- app/config/session.php | 2 +- .../api/PurchaseStatusController.php | 137 ++++++++++++++++++ app/models/PurchaseStatus.php | 3 + app/routes.php | 5 + composer.json | 6 +- 6 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 app/controllers/api/PurchaseStatusController.php diff --git a/app/config/examples/database.php b/app/config/examples/database.php index 8035cf6..684622b 100644 --- a/app/config/examples/database.php +++ b/app/config/examples/database.php @@ -23,9 +23,10 @@ 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', - 'database' => '', - 'username' => '', - 'password' => '', + 'database' => 'purchases', + 'username' => 'homestead', + 'password' => 'secret', + 'charset' => 'utf8', 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => '', diff --git a/app/config/session.php b/app/config/session.php index 059a939..b5a6c22 100644 --- a/app/config/session.php +++ b/app/config/session.php @@ -16,7 +16,7 @@ | */ - 'driver' => 'database', + 'driver' => 'file', /* |-------------------------------------------------------------------------- diff --git a/app/controllers/api/PurchaseStatusController.php b/app/controllers/api/PurchaseStatusController.php new file mode 100644 index 0000000..44aca05 --- /dev/null +++ b/app/controllers/api/PurchaseStatusController.php @@ -0,0 +1,137 @@ + [] + ]; + + $purSt = PurchaseStatus::all(); + + foreach($purSt as $pS){ + + $response['PurchaseStatuses'][] = [ + 'id' => $pS->id, + 'name' => $pS->name + ]; + } + + }catch (Exception $e){ + $statusCode = 400; + }finally{ + var_dump($response); + return Response::json($response, $statusCode); + } + + } + + + /** + * Show the form for creating a new resource. + * + * @return Response + */ + public function create() + { + // + } + + + /** + * Store a newly created resource in storage. + * + * @return Response + */ + public function store() + { + // + $input = Input::all(); + var_dump($input); + $purSt = new PurchaseStatus(); + $purSt->name = $input['name']; + $purSt->save(); + } + + + /** + * Display the specified resource. + * + * @param int $id + * @return Response + */ + public function show($id) + { + // + try{ + $purSt = PurchaseStatus::find($id); + $statusCode = 200; + $response = [ + 'PurchaseStatuses' => ['id' => $purSt->id, + 'name' => $purSt->name + ]]; + }catch (Exception $e){ + $statusCode = 400; + $response = [ + "error" => "Status doesn`t exists" + ]; + }finally{ + var_dump($response); + return Response::json($response, $statusCode); + } + } + + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return Response + */ + public function edit($id) + { + // + } + + + /** + * Update the specified resource in storage. + * + * @param int $id + * @return Response + */ + public function update($id) + { + // + } + + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return Response + */ + public function destroy($id) + { + // + } + + +} diff --git a/app/models/PurchaseStatus.php b/app/models/PurchaseStatus.php index e07222f..fddb5bc 100644 --- a/app/models/PurchaseStatus.php +++ b/app/models/PurchaseStatus.php @@ -6,6 +6,9 @@ * Date: 06.11.2014 * Time: 1:07 */ +namespace Goros6\Purchases\Models; +use Eloquent; + class PurchaseStatus extends Eloquent { public $timestamps = false; diff --git a/app/routes.php b/app/routes.php index 3e10dcf..a44f837 100644 --- a/app/routes.php +++ b/app/routes.php @@ -15,3 +15,8 @@ { return View::make('hello'); }); + +Route::group(array('prefix' => 'v1/api'), function() { + Route::resource('purchaseStatus', 'Goros6\\Purchases\\Controllers\\Api\\PurchaseStatusController'); +}); + diff --git a/composer.json b/composer.json index 72a75d7..e56e21e 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,11 @@ "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" - ] + ], + "psr-4":{ + "Goros6\\Purchases\\Controllers\\api\\": "app/controllers/api", + "Goros6\\Purchases\\Models\\": "app/models" + } }, "scripts": { "post-install-cmd": [