Skip to content

Commit

Permalink
User CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromesigg committed Feb 8, 2021
1 parent 82f279a commit b7975da
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 17 deletions.
125 changes: 125 additions & 0 deletions app/Http/Controllers/AdminUserController.php
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');
}
}
24 changes: 7 additions & 17 deletions resources/views/admin/people/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,21 @@
</header>
<div class="row">
<div class="col-sm-9">
{!! Form::model($pricelist, ['method' => 'PATCH', 'action'=>['AdminPricelistController@update', $pricelist->id], 'files' => true]) !!}
{!! Form::model($person, ['method' => 'PATCH', 'action'=>['AdminPersonController@update', $person->id], 'files' => true]) !!}
<div class="form-group">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'required']) !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('detail', 'Beschreibung:') !!}
{!! Form::text('detail', null, ['class' => 'form-control', 'required']) !!}
{!! Form::label('function', 'Funktion:') !!}
{!! Form::text('function', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('price', 'Preis:') !!}
{!! Form::text('price', null, ['class' => 'form-control', 'required']) !!}
{!! Form::label('photo_id', 'Photo:') !!}
{!! Form::file('photo_id', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('sort-index', 'Sort-Index:') !!}
{!! Form::text('sort-index', null, ['class' => 'form-control', 'required']) !!}
</div>
<div class="form-group">
{!! Form::label('archive_status_id', 'Archiv-Status:') !!}
{!! Form::select('archive_status_id', $archive_statuses, null, ['class' => 'form-control', 'required']) !!}
</div>


<div class="form-group">
{!! Form::submit('Preis Updaten', ['class' => 'btn btn-primary'])!!}
{!! Form::submit('Person Updaten', ['class' => 'btn btn-primary'])!!}
</div>
{!! Form::close()!!}
</div>
Expand Down
42 changes: 42 additions & 0 deletions resources/views/admin/users/edit.blade.php
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
60 changes: 60 additions & 0 deletions resources/views/admin/users/index.blade.php
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
3 changes: 3 additions & 0 deletions resources/views/includes/admin_sidenav.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<li>
<a href="{{route('histories.index')}}" ><i class="fas fa-history"></i>Geschichte</a>
</li>
<li>
<a href="{{route('users.index')}}" ><i class="fas fa-user"></i>Benutzer</a>
</li>
</ul>
</div>

Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
Route::resource('admin/testimonials', 'AdminTestimonialController');
Route::resource('admin/people', 'AdminPersonController');
Route::resource('admin/histories', 'AdminHistoryController');
Route::resource('admin/users', 'AdminUsersController');


});
Expand Down

0 comments on commit b7975da

Please sign in to comment.