Пример #1
0
<?php

header("Content-Type: application/json");
include "../models/CompanyRepository.php";
$config = (include "../db/config.php");
$db = new PDO($config["db"], $config["username"], $config["password"]);
$companies = new CompanyRepository($db);
switch ($_SERVER["REQUEST_METHOD"]) {
    case "GET":
        $result = $companies->getAll(array("name" => $_GET["name"], "id" => intval($_GET["id"])));
        break;
    case "POST":
        $result = $companies->insert(array("name" => $_POST["name"]));
        break;
    case "PUT":
        parse_str(file_get_contents("php://input"), $_PUT);
        $result = $companies->update(array("id" => intval($_PUT["id"]), "name" => $_PUT["name"]));
        break;
    case "DELETE":
        parse_str(file_get_contents("php://input"), $_DELETE);
        $result = $companies->remove(intval($_DELETE["id"]));
        break;
}
echo json_encode($result);
if (in_array($_SERVER["REQUEST_METHOD"], ["POST", "PUT", "DELETE"])) {
    require_once dirname(__FILE__) . '/../rules/prepare_rules.php';
}
Пример #2
0
 /**
  * Handle the registration of user.
  * 
  * @param type UserRegisterRequest $request 
  * @return type view
  */
 public function postRegister(UserRegisterRequest $request, UserRepository $user_gestion)
 {
     if ($request->user_type == 1) {
         if (is_null($request->siren)) {
             $errors = new MessageBag(['siren' => [trans('validation.required', ['attribute' => trans('form.siren')])]]);
             return Redirect::back()->withErrors($errors)->withInput(Input::except('siren'));
         }
         if (is_null($request->company_name)) {
             $errors = new MessageBag(['company_name' => [trans('validation.required', ['attribute' => trans('form.company_name')])]]);
             return Redirect::back()->withErrors($errors)->withInput(Input::except('company_name'));
         }
     }
     $user_id = $user_gestion->store($request);
     if ($request->user_type == 1) {
         $company_gestion = new CompanyRepository(new Company());
         $company_gestion->store($request, $user_id);
     }
     return Redirect::route('auth.register.success')->with('data_user', ['email' => $request->email, 'first_name' => $request->first_name, 'last_name' => $request->last_name]);
 }