-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
924 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Validation\Rule; | ||
|
||
class UserController extends Controller | ||
{ | ||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
} | ||
|
||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$users = User::latest()->with('roles')->paginate(6); | ||
|
||
return view('users.index', compact('users')); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
return view('users.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$this->validate($request, [ | ||
'name' => 'required|max:255', | ||
'email' => 'required|email|max:255|unique:users', | ||
'password' => 'required|min:6|confirmed', | ||
'roles' => 'required', | ||
]); | ||
|
||
$user = User::create([ | ||
'name' => $request->get('name'), | ||
'email' => $request->get('email'), | ||
'password' => bcrypt($request->get('password')), | ||
]); | ||
|
||
foreach ($request->get('roles') as $role => $id) { | ||
$user->toggleRole($role); | ||
} | ||
|
||
return redirect(route('usuarios.index')); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param \App\User $user | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show(User $user) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param \App\User $userEdit | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit(User $userEdit) | ||
{ | ||
return view('users.edit', compact('userEdit')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\User $userEdit | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, User $userEdit) | ||
{ | ||
$this->validate($request, [ | ||
'name' => 'required|max:255', | ||
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($userEdit->email, 'email')], | ||
'password' => 'sometimes|nullable|min:6|confirmed', | ||
'roles' => 'required', | ||
]); | ||
|
||
$userEdit->name = $request->get('name'); | ||
$userEdit->email = $request->get('email'); | ||
$request->get('password') ? $userEdit->password = bcrypt($request->get('password')) : ''; | ||
|
||
$userEdit->assignRoles(array_keys($request->get('roles'))); | ||
|
||
$userEdit->save(); | ||
|
||
return redirect(route('usuarios.index')); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\User $usuario | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(User $usuario) | ||
{ | ||
$usuario->delete(); | ||
return redirect(route('usuarios.index')); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\User; | ||
use App\ReporteTrimestral; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class ReporteTrimestralPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Determine whether the user can view the reporteTrimestral. | ||
* | ||
* @param \App\User $user | ||
* @param \App\ReporteTrimestral $reporteTrimestral | ||
* @return mixed | ||
*/ | ||
public function view(User $user, ReporteTrimestral $reporteTrimestral) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can create reporteTrimestrals. | ||
* | ||
* @param \App\User $user | ||
* @return mixed | ||
*/ | ||
public function create(User $user) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the reporteTrimestral. | ||
* | ||
* @param \App\User $user | ||
* @param \App\ReporteTrimestral $reporteTrimestral | ||
* @return mixed | ||
*/ | ||
public function update(User $user, ReporteTrimestral $reporteTrimestral) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the reporteTrimestral. | ||
* | ||
* @param \App\User $user | ||
* @param \App\ReporteTrimestral $reporteTrimestral | ||
* @return mixed | ||
*/ | ||
public function delete(User $user, ReporteTrimestral $reporteTrimestral) | ||
{ | ||
return $user->hasRole('admin'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class UserPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Determine whether the user can access index method. | ||
* | ||
* @param \App\User $user | ||
* @return mixed | ||
*/ | ||
public function index(User $user) | ||
{ | ||
return $user->hasRole('admin'); | ||
} | ||
|
||
|
||
/** | ||
* Determine whether the user can view the user. | ||
* | ||
* @param \App\User $user | ||
* @param \App\User $userEdit | ||
* @return mixed | ||
*/ | ||
public function view(User $user, User $userEdit) | ||
{ | ||
return $user->hasRole('admin') || $user->id == $userEdit->id; | ||
} | ||
|
||
/** | ||
* Determine whether the user can create users. | ||
* | ||
* @param \App\User $user | ||
* @return mixed | ||
*/ | ||
public function create(User $user) | ||
{ | ||
return $user->hasRole('admin'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the user. | ||
* | ||
* @param \App\User $user | ||
* @param \App\User $userEdit | ||
* @return mixed | ||
*/ | ||
public function update(User $user, User $userEdit) | ||
{ | ||
return $user->hasRole('admin') || $user->id == $userEdit->id; | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the user. | ||
* | ||
* @param \App\User $user | ||
* @param \App\User $userEdit | ||
* @return mixed | ||
*/ | ||
public function delete(User $user, User $userEdit) | ||
{ | ||
return $user->hasRole('admin') || $user->id == $userEdit->id; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.