Skip to content

Commit

Permalink
catching pdo exception on attach
Browse files Browse the repository at this point in the history
  • Loading branch information
MelonSmasher committed Nov 15, 2017
1 parent 2a49405 commit 76334f7
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions app/Http/Controllers/API/V1/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
use App\Http\Transformers\AccountTransformer;
use Dingo\Api\Exception\DeleteResourceFailedException;
use Dingo\Api\Exception\StoreResourceFailedException;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Events\Api\Account\AccountsViewed;
use App\Events\Api\Account\AccountViewed;
use App\Models\Access\Permission\Permission;
use App\Http\Models\API\LoadStatus;
use PDOException;

class AccountController extends ApiController
{
Expand Down Expand Up @@ -422,7 +424,12 @@ function assignDuty(Request $request)
}
}

$account->duties()->attach($data['duty_id']);

try {
$account->duties()->attach($data['duty_id']);
} catch (PDOException $exception) {
Log::warning('Failed to attach Account:' . $account->id . ' to Duty: ' . $data['duty_id'] . ' -- ' . $exception->getMessage() . ' -- ' . $exception->getTraceAsString());
}

//if ($account->duties()->attach($data['duty_id'])) {
event(new AssignedDuty($account, Duty::find($data['duty_id'])));
Expand Down Expand Up @@ -531,7 +538,11 @@ function assignSchool(Request $request)
}
}

$account->schools()->attach($data['school_id']);
try {
$account->schools()->attach($data['school_id']);
} catch (PDOException $exception) {
Log::warning('Failed to attach Account:' . $account->id . ' to School: ' . $data['school_id'] . ' -- ' . $exception->getMessage() . ' -- ' . $exception->getTraceAsString());
}

//if ($account->courses()->attach($data['course_id'])) {
event(new AssignedSchool($account, School::find($data['school_id'])));
Expand Down Expand Up @@ -637,7 +648,11 @@ function assignCourse(Request $request)
}
}

$account->courses()->attach($data['course_id']);
try {
$account->courses()->attach($data['course_id']);
} catch (PDOException $exception) {
Log::warning('Failed to attach Account:' . $account->id . ' to Course: ' . $data['course_id'] . ' -- ' . $exception->getMessage() . ' -- ' . $exception->getTraceAsString());
}

//if ($account->courses()->attach($data['course_id'])) {
event(new AssignedCourse($account, Course::find($data['course_id'])));
Expand Down Expand Up @@ -744,7 +759,11 @@ function assignDepartment(Request $request)
}
}

$account->departments()->attach($data['department_id']);
try {
$account->departments()->attach($data['department_id']);
} catch (PDOException $exception) {
Log::warning('Failed to attach Department:' . $account->id . ' to Department: ' . $data['department_id'] . ' -- ' . $exception->getMessage() . ' -- ' . $exception->getTraceAsString());
}

//if ($account->departments()->attach($data['department_id'])) {
event($account, new AssignedDepartment($account, Department::find($data['department_id'])));
Expand Down Expand Up @@ -850,7 +869,11 @@ function assignRoom(Request $request)
}
}

$account->rooms()->attach($data['room_id']);
try {
$account->rooms()->attach($data['room_id']);
} catch (PDOException $exception) {
Log::warning('Failed to attach Account:' . $account->id . ' to Room: ' . $data['room_id'] . ' -- ' . $exception->getMessage() . ' -- ' . $exception->getTraceAsString());
}

//if ($account->rooms()->attach($data['room_id'])) {
event($account, new AssignedRoom($account, Room::find($data['room_id'])));
Expand Down

0 comments on commit 76334f7

Please sign in to comment.