Add events types modification for management
Diff
app/Http/routes.php | 5 ++++-
app/Models/Event.php | 2 +-
resources/views/layouts/nav.blade.php | 5 +++++
resources/views/management/event-types-form.blade.php | 37 +++++++++++++++++++++++++++++++++++++
resources/views/management/event-types.blade.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
app/Http/Controllers/Management/EventTypeController.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 171 insertions(+), 2 deletions(-)
@@ -92,7 +92,10 @@
'namespace' => 'Management',
'middleware' => 'is:management'
], function () {
Route::get('event-type', ['as' => 'event-type', 'uses' => 'EventTypeController@index']);
Route::get('event-type/add', ['as' => 'event-type.form', 'uses' => 'EventTypeController@form']);
Route::put('event-type', ['as' => 'event-type.add', 'uses' => 'EventTypeController@add']);
Route::delete('event-type/{id}', ['as' => 'event-type.delete', 'uses' => 'eventtypecontroller@delete']);
});
Route::group([
@@ -30,7 +30,7 @@
* @method static Builder|Event whereYear($value)
* @method static Builder|Event whereDay($value)
* @method static Builder|Event whereHour($value)
* @method static Builder|Event whereEventTypesId($value)
* @method static Builder|Event whereEventTypeId($value)
* @method static Builder|Event whereCreatedAt($value)
* @method static Builder|Event whereUpdatedAt($value)
* @method static Builder|Event whereDeletedAt($value)
@@ -79,6 +79,11 @@
<div class="zpan-drawer-separator"></div>
<span class="mdl-navigation__link" href>Management</span>
<a class="mdl-navigation__link {{ is_route('dashboard::management::event-type') ? 'is-active' : '' }}"
href="{{ route('dashboard::management::event-type') }}">
<i class="material-icons">settings_applications</i> Event Types
</a>
@endif
@if(auth()->user()->isAdmin())
@@ -1,0 +1,37 @@
@extends(Request::ajax() ? 'layouts.ajax-main' : 'layouts.main')
@section('title'){{ _('Add Request Line Ban') }} @endsection
@section('page-title')Management <i class="material-icons">chevron_right</i> Event Types <i
class="material-icons">chevron_right</i> Add @endsection
@section('content')
<div class="mdl-card mdl-cell mdl-cell--12-col mdl-shadow--2dp">
<div class="mdl-card__supporting-text">
<h4>{{ _('Add Event Type') }}</h4>
<p>{{ _('Here you can new event types for the events staff to use.') }}</p>
<form role="form" method="POST" action="{{ route('dashboard::management::event-type.add') }}">
{{ csrf_field() }}
{{ method_field('put') }}
<fieldset
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label {{ $errors->has('name') ? 'is-invalid' : '' }}">
<input type="text" class="mdl-textfield__input" id="name" name="name"
value="{{ old('name') }}">
<label class="mdl-textfield__label" for="name">Name</label>
@if ($errors->has('name'))
<span class="mdl-textfield__error">{{ $errors->first('name') }}</span>
@endif
</fieldset>
<fieldset class="form-group">
<button type="submit"
class="mdl-button mdl-button--raised mdl-button--colored mdl-js-button mdl-js-ripple-effect">
<i class="fa fa-btn fa-plus"></i> {{ _('Save') }}
</button>
</fieldset>
</form>
</div>
</div>
@endsection
@@ -1,0 +1,50 @@
@extends(Request::ajax() ? 'layouts.ajax-main' : 'layouts.main')
@section('title'){{ _('Event Types') }} @endsection
@section('page-title')Management <i class="material-icons">chevron_right</i> Event Types @endsection
@section('content')
<div class="table-responsive">
{!! $types->links() !!}
<table class="mdl-data-table mdl-js-data-table mdl-cell mdl-cell--12-col mdl-shadow--2dp">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">#</th>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Amount of Events</th>
<th class="mdl-data-table__cell--non-numeric">Added</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($types as $type)
<tr>
<td class="mdl-data-table__cell--non-numeric">{{ $type->id }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ $type->name }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ App\Models\Event::whereEventTypeId($type->id)->count() }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ $type->created_at->diffForHumans() }}</td>
<td>
<form action="{{ route('dashboard::management::event-type.delete', $type->id) }}" method="post">
{{ csrf_field() }}
{{ method_field('delete') }}
<button class="mdl-button mdl-js-button mdl-button--icon mdl-button--colored">
<i class="material-icons delete">delete forever</i>
</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
{!! $types->links() !!}
</div>
<a class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored" id="add"
href="{{ route('dashboard::management::event-type.form') }}">
<i class="material-icons">add</i>
</a>
@endsection
@@ -1,0 +1,74 @@
<?php
namespace App\Http\Controllers\Management;
use App\Http\Controllers\Controller;
use App\Models\EventType;
use Illuminate\Http\Request;
/**
* Allow management to add and remove event types.
*
* @author Jordan Doyle <jordan@doyle.wf>
*/
class EventTypeController extends Controller
{
/**
* Show the manager a list of types.
*
* @return mixed
*/
public function index()
{
return view('management.event-types', [
'types' => EventType::orderBy('id', 'desc')->paginate(15)
]);
}
/**
* Show the manager a form to add a new event type.
*
* @return mixed
*/
public function form()
{
return view('management.event-types-form');
}
/**
* Add an event type
*
* @param Request $request
* @return mixed
*/
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required|min:3'
]);
$ban = new EventType();
$ban->name = $request->get('name');
$ban->save();
return redirect()->route('dashboard::management::event-type')->with('msg', [
'type' => 'success',
'msg' => _('Successfully added a new event type.')
]);
}
/**
* Remove an event type.
*
* @param int $id id of the event type to delete.
* @return mixed
*/
public function delete(int $id)
{
EventType::findOrFail($id)->delete();
return redirect()->back()->with('msg', [
'type' => 'success',
'msg' => _('Successfully removed the event type.')
]);
}
}