Skip to content

Commit

Permalink
Modifying servers and users to use mass assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Ball committed Apr 8, 2015
1 parent 09137dc commit 1d90af0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
1 change: 0 additions & 1 deletion app/Http/Controllers/CommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class CommandController extends Controller
* Display a listing of before/after commands for the supplied stage
*
* @param Project $project
* @param int $project_id
* @param string $action Either clone, install, activate or purge
* @return Response
*/
Expand Down
18 changes: 11 additions & 7 deletions app/Http/Controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ public function store(StoreServerRequest $request)
*/
public function update(Server $server, StoreServerRequest $request)
{

$fields = $request->only(
'name',
'user',
'ip_address',
'path',
'project_id'
);

if ($server->ip_address != $request->ip_address) {
$server->status = Server::UNTESTED;
$fields['status'] = Server::UNTESTED;
}

$server->name = $request->name;
$server->user = $request->user;
$server->ip_address = $request->ip_address;
$server->path = $request->path;
$server->project_id = $request->project_id;
$server->save();
$server->update($fields);

return $server;
}
Expand Down
28 changes: 16 additions & 12 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class UserController extends Controller
public function index()
{
$users = User::all();

foreach ($users as $user) {
$user->created = $user->created_at->format('jS F Y g:i:s A');
}
Expand All @@ -36,17 +37,19 @@ public function index()
*
* @param StoreUserRequest $request
* @return Response
* @todo Use mass assignment if possible
*/
public function store(StoreUserRequest $request)
{
$user = new User;
$user->name = $request->name;
$user->email = $request->email;
$user->password = bcrypt($request->password);
$user->save();
$fields = $request->only(
'name',
'email'
);

$fields['password'] = bcrypt($request->password);

$user->created = $user->created_at->format('jS F Y g:i:s A');
$user = User::create($fields);

$user->created = $user->created_at->format('jS F Y g:i:s A');

return $user;
}
Expand All @@ -57,18 +60,19 @@ public function store(StoreUserRequest $request)
* @param User $user
* @param StoreUserRequest $request
* @return Response
* @todo Use mass assignment if possible
*/
public function update(User $user, StoreUserRequest $request)
{
$user->name = $request->name;
$user->email = $request->email;
$fields = $request->only(
'name',
'email'
);

if (isset($request->password)) {
$user->password = bcrypt($request->password);
$fields['password'] = bcrypt($request->password);
}

$user->save();
$user->update($fields);

$user->created = $user->created_at->format('jS F Y g:i:s A');

Expand Down

0 comments on commit 1d90af0

Please sign in to comment.