help desk create view

This commit is contained in:
merdan 2020-05-01 15:54:03 +05:00
parent ea3a415f95
commit d6f8bcdf49
6 changed files with 120 additions and 10 deletions

View File

@ -9,6 +9,7 @@ use App\Http\Requests\HelpTicketRequest;
use App\Models\HelpTicket;
use App\Models\HelpTicketComment;
use App\Models\HelpTopic;
use Illuminate\Support\Facades\Log;
class HelpDeskController extends Controller
{
@ -33,16 +34,22 @@ class HelpDeskController extends Controller
}
public function store(HelpTicketRequest $request){
//
// try{
$ticekt = HelpTicket::create([
'name' => $request->get('name'),
'email' => $request->get('email'),
'text' => $request->get('text'),
'phone' => $request->get('phone'),
'subject' => $request->get('subject'),
'ticket_category_id' => $request->get('topic')
]);
$ticekt = HelpTicket::create([
'name' => $request->get('name'),
'email' => $request->get('email'),
'text' => $request->get('text'),
'phone' => $request->get('phone'),
'subject' => $request->get('subject'),
'ticket_category_id' => $request->get('topic'),
'attachment' => $request->get('attachment')
]);
// }
// catch (\Exception $exception){
// Log::error($exception);
// }
//todo fire event notify admin by mail, attachment
return redirect()->route('help.show',['code' => $ticekt->code]);
@ -64,6 +71,10 @@ class HelpDeskController extends Controller
$ticket->update(['status' => 'pending']) ;
if($request->has('attachment')){
}
//todo notify, attachment
return redirect()->route('help.show',['code' => $code]);

View File

@ -26,7 +26,8 @@ class HelpTicketCommentRequest extends FormRequest
public function rules()
{
return [
'text' => 'required'
'text' => 'required',
'attachment' => 'max:1024|mimes:pdf,jpg,png,jpeg,txt'
];
}

View File

@ -29,6 +29,7 @@ class HelpTicketRequest extends FormRequest
'email' => 'required|email',
'topic' => 'required',
'text' => 'required',
'attachment' => 'image|max:1024'
];
}

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use Illuminate\Support\Str;
class HelpTicket extends Model
{
@ -59,6 +60,36 @@ class HelpTicket extends Model
| MUTATORS
|--------------------------------------------------------------------------
*/
public function setAttachmentAttribute($value){
$attribute_name = "attachment";
$disk = config('filesystems.default'); // or use your own disk, defined in config/filesystems.php
$destination_path = "help"; // path relative to the disk above
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);
// 1. Generate a filename.
$filename = md5($value.time()).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the public path to the database
// but first, remove "public/" from the path, since we're pointing to it from the root folder
// that way, what gets saved in the database is the user-accesible URL
$public_destination_path = Str::replaceFirst('public/', '', $destination_path);
$this->attributes[$attribute_name] = $public_destination_path.'/'.$filename;
}
}
/**
* Boot all of the bootable traits on the model.
*/
@ -69,5 +100,16 @@ class HelpTicket extends Model
static::creating(function ($ticket) {
$ticket->code = strtoupper(str_random(5)) . date('jn');
});
static::deleting(function($obj) {
$disk = config('filesystems.default');
\Storage::disk($disk)->delete($obj->seats_image);
if (count((array)$obj->images)) {
foreach ($obj->images as $file_path) {
\Storage::disk('uploads')->delete($file_path);
}
}
});
}
}

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use Illuminate\Support\Str;
class HelpTicketComment extends Model
{
@ -55,4 +56,54 @@ class HelpTicketComment extends Model
| MUTATORS
|--------------------------------------------------------------------------
*/
//todo use trait for image upload
public function setAttachmentAttribute($value){
$attribute_name = "attachment";
$disk = config('filesystems.default'); // or use your own disk, defined in config/filesystems.php
$destination_path = "help"; // path relative to the disk above
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);
// 1. Generate a filename.
$filename = md5($value.time()).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the public path to the database
// but first, remove "public/" from the path, since we're pointing to it from the root folder
// that way, what gets saved in the database is the user-accesible URL
$public_destination_path = Str::replaceFirst('public/', '', $destination_path);
$this->attributes[$attribute_name] = $public_destination_path.'/'.$filename;
}
}
/**
* Boot all of the bootable traits on the model.
*/
public static function boot()
{
parent::boot();
static::deleting(function($obj) {
$disk = config('filesystems.default');
\Storage::disk($disk)->delete($obj->seats_image);
if (count((array)$obj->images)) {
foreach ($obj->images as $file_path) {
\Storage::disk('uploads')->delete($file_path);
}
}
});
}
}

View File

@ -33,6 +33,10 @@
'rows' => 5
)) !!}
</div>
<div class="form-group">
{!! Form::label('attachment', trans("ClientSide.attachment"), array('class'=>'control-label')) !!}
{!! Form::file('attachment') !!}
</div>
{!! Form::submit(trans("ClientSide.create_ticket"), ['class'=>"btn btn-success"]) !!}
</form>
</div>