Created
February 14, 2016 04:34
-
-
Save iamkirkbater/ef17283851494ea578d6 to your computer and use it in GitHub Desktop.
Converting to Laravel Validator instead of doing the logic in the controller:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$start = $request->get('start'); | |
$end = $request->get('end'); | |
$project = $request->get('project_id'); | |
$task = $request->get('task_id'); | |
if ( ! $start || ! is_int($start)) | |
{ | |
return new Response(["error" => true, "message" => "Start time is not valid."], HTTP::BAD_REQUEST); | |
} | |
if ( ! $end || ! is_int($end)) | |
{ | |
return new Response(["error" => true, "message" => "End time is not valid."], HTTP::BAD_REQUEST); | |
} | |
if ($end < $start) | |
{ | |
return new Response(["error" => true, "message" => "End time is before start time."], HTTP::BAD_REQUEST); | |
} | |
if ( ! $project ) | |
{ | |
return new Response(["error" => true, "message" => "Project not specified."], HTTP::BAD_REQUEST); | |
} | |
$project = Project::find($project); | |
if ( ! $project ) | |
{ | |
return new Response(["error" => true, "message" => "Invalid project id specified."], HTTP::BAD_REQUEST); | |
} | |
if ( ! $project->status ) | |
{ | |
return new Response(["error" => true, "message" => "Project is not active."], HTTP::BAD_REQUEST); | |
} | |
if ( ! $task ) | |
{ | |
return new Response(["error" => true, "message" => "Task not provided."], HTTP::BAD_REQUEST); | |
} | |
$task = Task::find($task); | |
if ( ! $task ) | |
{ | |
return new Response(["error" => true, "message" => "Task not found."], HTTP::BAD_REQUEST); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment