-
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
1 parent
82f279a
commit b7975da
Showing
6 changed files
with
238 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Role; | ||
use App\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class AdminUserController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
// | ||
$users = User::paginate(10); | ||
return view('admin.users.index', compact('users')); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
// | ||
if(!Auth::user()->isAdmin()){ | ||
$roles = Role::where('is_admin', false)->pluck('name','id')->all(); | ||
} else { | ||
$roles = Role::pluck('name','id')->all(); | ||
|
||
} | ||
return view('admin.users.create', compact('roles')); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// | ||
if(trim($request->password) == ''){ | ||
$input = $request->except('password'); | ||
} | ||
else{ | ||
$input = $request->all(); | ||
$input['password'] = bcrypt($request->password); | ||
} | ||
|
||
User::create($input); | ||
|
||
return redirect('/admin/users'); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit($id) | ||
{ | ||
// | ||
$user = User::findOrFail($id); | ||
$roles = Role::pluck('name','id')->all(); | ||
|
||
return view('admin.users.edit', compact('user', 'roles')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, $id) | ||
{ | ||
// | ||
$user = User::findOrFail($id); | ||
|
||
if(trim($request->password) == ''){ | ||
$input = $request->except('password'); | ||
} | ||
else{ | ||
$input = $request->all(); | ||
$input['password'] = bcrypt($request->password); | ||
} | ||
|
||
$user->update($input); | ||
return redirect('/admin/users'); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
// | ||
User::findOrFail($id)->delete(); | ||
return redirect('/admin/users'); | ||
} | ||
} |
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,42 @@ | ||
@extends('layouts.admin') | ||
@section('content') | ||
|
||
<section> | ||
<div class="container-fluid"> | ||
<header> | ||
<h1 class="h3 display">Benutzer bearbeiten</h1> | ||
</header> | ||
<div class="row"> | ||
<div class="col-sm-9"> | ||
{!! Form::model($user, ['method' => 'PATCH', 'action'=>['AdminUserController@update', $user->id], 'files' => true]) !!} | ||
<div class="form-group"> | ||
{!! Form::label('username', 'Name:') !!} | ||
{!! Form::text('username', null, ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::label('role_id', 'Role:') !!} | ||
{!! Form::select('role_id', [''=>'Wähle Rolle'] + $roles, null, ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::label('is_active', 'Status:') !!} | ||
{!! Form::select('is_active', array(1 => "Aktiv", 0 => 'Archiviert'), null, ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::label('password', 'Password:') !!} | ||
{!! Form::password('password', ['class' => 'form-control']) !!} | ||
</div> | ||
|
||
|
||
<div class="form-group"> | ||
{!! Form::submit('Benutzer Updaten', ['class' => 'btn btn-primary'])!!} | ||
</div> | ||
{!! Form::close()!!} | ||
</div> | ||
</div> | ||
<div class="row"> | ||
@include('includes.form_error') | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
@endsection |
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,60 @@ | ||
@extends('layouts.admin') | ||
|
||
@section('content') | ||
<section> | ||
<div class="container-fluid"> | ||
|
||
<header> | ||
<h1>Benutzer</h1> | ||
</header> | ||
|
||
<div class="row"> | ||
<div class="col-sm-3"> | ||
{!! Form::open(['method' => 'POST', 'action'=>'AdminUsersController@store']) !!} | ||
<div class="form-group"> | ||
{!! Form::label('username', 'Name:') !!} | ||
{!! Form::text('username', null, ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::label('role_id', 'Role:') !!} | ||
{!! Form::select('role_id', [''=>'Wähle Rolle'] + $roles, null, ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::label('is_active', 'Status:') !!} | ||
{!! Form::select('is_active', array(1 => "Aktiv", 0 => 'Archiviert'), null, ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::label('password', 'Password:') !!} | ||
{!! Form::password('password', ['class' => 'form-control']) !!} | ||
</div> | ||
<div class="form-group"> | ||
{!! Form::submit('Benutzer erstellen', ['class' => 'btn btn-primary'])!!} | ||
</div> | ||
{!! Form::close()!!} | ||
</div> | ||
<div class="col-sm-9"> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th scope="col" width="10%">Benutzername</th> | ||
<th scope="col" width="30%">Rolle</th> | ||
<th scope="col" width="40%">Aktiv</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@if($users) | ||
@foreach ($users as $user) | ||
<tr> | ||
<td><a href="{{route('users.edit', $user->id)}}">{{$user->username}}</a></td> | ||
<td>{{$user->role['name']}}</td> | ||
<td>{{$user->isactive ? 'Aktiv' : 'Archiviert'}}</td> | ||
</tr> | ||
@endforeach | ||
@endif | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
@endsection |
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