Last active
August 29, 2015 14:07
-
-
Save tonysm/e4fd61fe7db26a6ea7cf to your computer and use it in GitHub Desktop.
Controllers e mecanismos de transporte
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
| <?php | |
| use Acme\Repositories\TaskRepository; | |
| use Acme\Repositories\UserRepository; | |
| use Acme\Mailers\UserMailer; | |
| class TasksController extends Controller | |
| { | |
| /** | |
| * @var Acme\Repositories\TaskRepository | |
| */ | |
| protected $tasks; | |
| /** | |
| * @var Acme\Repositories\UserRepository | |
| */ | |
| protected $users; | |
| /** | |
| * @var Acme\Mailers\UserMailer | |
| */ | |
| protected $mailer; | |
| /** | |
| * @param TaskRepository $tasks | |
| * @param UserRepository $users | |
| * @param UserMailer $mailer | |
| */ | |
| function __construct( | |
| TaskRepository $tasks, | |
| UserRepository $users, | |
| UserMailer $mailer | |
| ) { | |
| $this->tasks = $tasks; | |
| $this->users = $users; | |
| $this->mailer = $mailer; | |
| } | |
| /** | |
| * @param string|int $task_id | |
| * @param string|int $user_id | |
| * @return mixed | |
| */ | |
| public function transfer($task_id, $user_id) | |
| { | |
| $userTo = $this->users->find($user_id); | |
| $task = $this->tasks->find($task_id); | |
| $task->setUser($userTo); | |
| if ( ! $this->tasks->save($task)) | |
| { | |
| return Redirect::to('tasks') | |
| ->withErrors($this->tasks->getErrors()); | |
| } | |
| $this->mailer->notifyTaskTransference($task, $userTo); | |
| return Redirect::to('tasks') | |
| ->with(['message' => Lang::get('tasks.transfer.success']); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment