Skip to content

Commit

Permalink
Commit #29 - Adding Event features in admin section
Browse files Browse the repository at this point in the history
  • Loading branch information
sharbel93 committed Jan 11, 2019
1 parent 08c0ce1 commit 103832b
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ npm-debug.log
yarn-error.log
.env
.phpunit.result.cache
/public/events/images/*
/public/posts/images/*
76 changes: 69 additions & 7 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Purifier;
use Session;
use App\Event;
use File;
use Intervention\Image\ImageManagerStatic as Image;
class EventController extends Controller
{
public function __construct()
Expand All @@ -18,8 +21,8 @@ public function __construct()
*/
public function index()
{
$event = Event::all();
return view('manage.events.index')->withEvents($event);
$events = Event::orderBy('created','ASC')->get();
return view('manage.events.index')->withEvents($events);
}

/**
Expand All @@ -29,7 +32,7 @@ public function index()
*/
public function create()
{
//
return view('manage.events.create');
}

/**
Expand All @@ -40,7 +43,30 @@ public function create()
*/
public function store(Request $request)
{
//
$this->validate($request, array(
'title' => 'required|max:255',
'venue' => 'required|max:255',
'location' => 'required|max:255',
'thumbnail' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
));

$event = new Event;
$event->title = $request->title;
$event->venue = $request->venue;
$event->location = $request->location;
$event->created = $request->created;
$event->content = Purifier::clean($request->content);

if( $request->hasFile('thumbnail') ) {
$event_thumbnail = $request->file('thumbnail');
$filename = str_slug($request->title, $separator = '-').date('His'). '.jpg';
$location = public_path('/events/images/' . $filename );
Image::make($event_thumbnail)->resize(800,400)->save($location);
$event->thumbnail = $filename;
}

$event->save();
return redirect()->route('events.show', $event->id)->with('success', 'Event Created Successfully');
}

/**
Expand All @@ -51,9 +77,11 @@ public function store(Request $request)
*/
public function show($id)
{
//
$event = Event::findOrFail($id);
return view('manage.events.show')->withEvent($event);
}


/**
* Show the form for editing the specified resource.
*
Expand All @@ -62,7 +90,8 @@ public function show($id)
*/
public function edit($id)
{
//
$event = Event::findOrFail($id);
return view('manage.events.edit')->withEvent($event)->with('success', 'Edited Successfully');
}

/**
Expand All @@ -74,7 +103,40 @@ public function edit($id)
*/
public function update(Request $request, $id)
{
//
$this->validate($request, array(
'title' => 'required|max:255',
'venue' => 'required|max:255',
'location' => 'required|max:255',
'thumbnail' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
));

$event = Event::findOrFail($id);
$event->title = $request->input('title');
$event->venue = $request->input('venue');
$event->location = $request->input('location');
$event->created = $request->input('created');
$event->content = Purifier::clean($request->input('content'));

// Check if file is present
if( $request->hasFile('thumbnail') ) {
$event_thumbnail = $request->file('thumbnail');
$filename = str_slug($request->title, $separator = '-').date('His'). '.png';
$location = public_path('/events/images/' . $filename );
Image::make($event_thumbnail)->resize(800, 400)->save( $location );
$oldFilename = $event->thumbnail;

// Delete the old photo
if(!$event->thumbnail == null){
$oldFilename = $event->thumbnail;
$filename1 = public_path().'/events/images/'.$oldFilename;
\File::delete($filename1);
}

// update database
$event->thumbnail = $filename;
}
$event->save();
return redirect()->route('events.show', $event->id)->with('success', 'The event is successfully saved!');
}

/**
Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function update(Request $request, $id)
'slug' => "required|alpha_dash |min:5 |max: 255|unique:posts,slug, $id",
'category_id' => 'required|integer',
'content'=> 'required',
'thumbnail' => 'sometimes|image'
'thumbnail' => 'required|image'
));

// Save the data to the database
Expand Down Expand Up @@ -203,12 +203,12 @@ public function update(Request $request, $id)


// Delete the old photo
// if(!$post->image == null){
// $oldFilename = $post->image;
// $filename1 = public_path().'/posts/images/'.$oldFilename;
// \File::delete($filename1);
// }
Storage::delete($oldFilename);
if(!$post->image == null){
$oldFilename = $post->image;
$filename1 = public_path().'/posts/images/'.$oldFilename;
\File::delete($filename1);
}
// Storage::delete($oldFilename);

// update database
$post->image = $filename;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SermonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct()
*/
public function index()
{
$sermons = Sermon::all();
$sermons = Sermon::orderBy('created','ASC')->get();
return view('manage.sermons.index')->withSermons($sermons);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up()
$table->string('title');
$table->string('venue');
$table->string('location');
$table->string('image');
$table->string('thumbnail');
$table->date('created');
$table->longText('content');
$table->timestamps();
Expand Down
62 changes: 48 additions & 14 deletions resources/views/manage/events/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,64 @@
<div class="product-status-wrap drp-lst">
<div class="container-fluid">
<div class="col-md-6">
<h2>Daily Inspiration</h2>
<h2>Create Event</h2>
</div>
<div class="col-md-6 ">
<a href="{{route('daily.create')}}" class=" m-r-10 button is-primary is-pulled-right ">Create
Dailies</a>
<a href="{{route('daily.create')}}" class=" m-r-10 button is-primary is-pulled-right
">Create
Dailies</a>

<a href="{{route('events.index')}}" class=" m-r-10 button is-primary is-pulled-right
">All
Events</a>

</div>
<div class="col-md-12">

<form>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Title">
<form action="{{ route('events.store') }}" method="post" enctype="multipart/form-data" >
{{ csrf_field()}}
<div class="col-md-6">
<div class="form-group">
<label for="title">Event Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Event Title">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="venue">Event Venue</label>
<input type="text" class="form-control" id=" venue" name="venue"
placeholder="Event Venue">
</div>
</div>

<div class="col-md-4">
<div class="form-group">
<label for="location">Event Location</label>
<input type="text" class="form-control" id="location" name="location"
placeholder="Event Location">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="created">Event Date</label>
<input type="date" class="form-control" id="created" name="created"
>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="by">By</label>
<input type="text" class="form-control" id="by" name="by"
placeholder="Author's name">
</div>
</div>


<div class="form-group">
<label for="by">By</label>
<input type="text" class="form-control" id="by" name="by"
placeholder="Author's name">
<label for="thumbnail">Upload Image</label>
<input type="file" class="form-control" id="thumbnail" name="thumbnail"
>
</div>

<div class="form-group">
<label for="content">Message Content</label>
<label for="content">Event Content</label>
<textarea type="text" class="form-control" id="content" name="content"
></textarea>
</div>
Expand Down
80 changes: 80 additions & 0 deletions resources/views/manage/events/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@extends('layouts.manage')

@section('styles')
<link rel="stylesheet" href="{{asset('/js/summernote.css')}}">
@endsection

@section('content')

Expand All @@ -9,7 +12,54 @@
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="product-status-wrap drp-lst">
<div class="container-fluid">
<div class="row m-b-20">
<div class="col-md-6 col-sm-4 col-xs-4">
<h1 > Edit Event</h1>
</div>
<div class="col-md-6 col-sm-8 col-xs-8">
<a href="{{route('events.index')}}" class="button is-primary is-pulled-right">
<i class="fa fa-user-add m-r-10"></i> All Events
</a>
</div>
</div>
{!! Form::model($event, ['route' => ['events.update', $event->id], 'method' => 'PUT', 'files' =>
true] ) !!}
<div class="row">


<div class="col-lg-12 col-md-12">

{{ Form::label('title', 'Event Title:') }}
{{ Form::text('title', null, ['class' => 'form-control form-control-lg'] , ['placeholder' => '.form-control-lg']) }}

{{ Form::label('venue', 'Event Venue:') }}
{{ Form::text('venue', null, ['class' => 'form-control form-control-lg'] ,
['placeholder' => '.form-control-lg']) }}

{{ Form::label('location', 'Event Location:') }}
{{ Form::text('location', null, ['class' => 'form-control form-control-lg'] ,
['placeholder' => '.form-control-lg']) }}

{{ Form::label('created', 'Event Date', ['class' => 'm-t-15']) }}
{{ Form::date('created', null, ['class' => 'form-control form-control-lg']) }}

{{ Form::label('thumbnail', 'Update Image',['class' => 'mb-2 my-2']) }}
{{ Form::file('thumbnail') }}
<img src="{{ asset('/events/images/'.$event->thumbnail) }}" alt="image">
<br>

{{ Form::label('content', 'Event Content:', ['class' => 'form-spacing-top']) }}
{{ Form::textarea('content',null, ['class' => 'form-control']) }}

{{ Form::submit('Save Changes', ['class' => ' m-t-20 btn btn-success btn-block']) }}
</div>



</div> <!-- end od .row (form) -->
{!! Form::close() !!}
</div>
</div>
</div>
</div>
Expand All @@ -18,3 +68,33 @@

@stop

@section('scripts')
<script>
$(document).ready(function(){
$('#content').summernote({
height: 180,
toolbar: [
['style', ['style','bold', 'italic', 'underline', 'clear']],
['font', ['fontname','strikethrough', 'superscript', 'subscript']],
['height', ['height']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph', ]],
['insert',[ 'link', 'video', 'table', 'hr']],
['formatH6'],
['misc',['fullscreen', 'codeview', 'undo', 'redo', 'help']]
],
popover: {
link: [
['link', ['linkDialogShow', 'unlink']]
]
}
});
});
</script>
<script src="{{asset('/js/summernote.min.js')}}"></script>
@endsection
Loading

0 comments on commit 103832b

Please sign in to comment.