/** * @param $projectId * @param $memberId * @return array */ public function destroy($projectId, $memberId) { try { if ($this->model->findOrFail($projectId)->members()->detach($memberId)) { return ['success' => true, 'message' => 'Registro excluído']; } return ['error' => true, 'message' => 'Erro desconhecido ao tentar excluir o registro']; } catch (\Exception $e) { return ["error" => true, "message" => $e->getMessage()]; } }
public function delete($id) { if (is_null(ProjectMember::find($id))) { return Errors::invalidId($id); } $this->repository->delete($id); return ['message' => "Registro deletado!"]; }
public function delete($id) { $pm = ProjectMember::find($id); if (is_null($pm)) { return Errors::invalidId($id); } // Lembrete: a verificacao se o usuario autenticado eh o dono do projeto ja foi // feita via middleware. Basta agora testar se o membro nao eh o usuario autenticado $user_id = \Authorizer::getResourceOwnerId(); if ($user_id == $pm->user_id) { return Errors::basic("Voce eh dono do projeto e portanto nao pode se excluir dele"); } $this->repository->delete($id); return ['message' => "Registro deletado!"]; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('project_members')->delete(); for ($i = 1;; $i++) { if ($i > 50) { break; } for (;;) { $projectId = \CodeProject\Entities\Project::all()->lists('id')->random(1); $userId = \CodeProject\Entities\User::all()->lists('id')->random(1); if (\CodeProject\Entities\ProjectMember::where('project_id', $projectId)->where('member_id', $userId)->count() == 0) { \CodeProject\Entities\ProjectMember::create(['project_id' => $projectId, 'member_id' => $userId]); break; } } } }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); /*Desativa chave etrangeira*/ DB::statement('SET FOREIGN_KEY_CHECKS=0;'); \CodeProject\Entities\ProjectTask::truncate(); \CodeProject\Entities\ProjectMember::truncate(); \CodeProject\Entities\ProjectNote::truncate(); \CodeProject\Entities\Project::truncate(); \CodeProject\Entities\Client::truncate(); \CodeProject\Entities\User::truncate(); $this->call(UserTableSeeder::class); $this->call(ClientTableSeeder::class); $this->call(ProjectTableSeeder::class); $this->call(ProjectNoteTableSeeder::class); $this->call(ProjectMembersTableSeeder::class); $this->call(ProjectTasksTableSeeder::class); /*ativa chave estrangeira*/ DB::statement('SET FOREIGN_KEY_CHECKS=1;'); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::statement('SET FOREIGN_KEY_CHECKS=0;'); Project::truncate(); User::truncate(); Client::truncate(); ProjectNote::truncate(); ProjectTask::truncate(); ProjectMember::truncate(); OauthClient::truncate(); DB::statement('SET FOREIGN_KEY_CHECKS=1;'); $this->call(ClientTableSeeder::class); $this->call(UserTableSeeder::class); $this->call(ProjectTableSeeder::class); $this->call(ProjectNoteTableSeeder::class); $this->call(ProjectTaskTableSeeder::class); $this->call(ProjectMemberTableSeeder::class); $this->call(OauthClientSeeder::class); Model::reguard(); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::statement('SET foreign_key_checks = 0'); ProjectNote::truncate(); ProjectTask::truncate(); ProjectMember::truncate(); ProjectFile::truncate(); Project::truncate(); Client::truncate(); User::truncate(); OAuthClient::truncate(); DB::statement('SET foreign_key_checks = 1'); $this->call(UserTableSeeder::class); $this->call(ClientTableSeeder::class); $this->call(ProjectTableSeeder::class); $this->call(ProjectNoteTableSeeder::class); $this->call(ProjectMemberTableSeeder::class); $this->call(ProjectTaskTableSeeder::class); $this->call(OAuthClientTableSeeder::class); Model::reguard(); }
/** * Run the database seeds. * * @return void */ public function run() { \CodeProject\Entities\ProjectMember::truncate(); factory(\CodeProject\Entities\ProjectMember::class, 10)->create(); }
/** * Run the database seeds. * * @return void */ public function run() { ProjectMember::truncate(); factory(ProjectMember::class, 50)->create(); }