last_sender added to tickets
This commit is contained in:
parent
9f6391fe7c
commit
1b5537a94a
|
|
@ -20,8 +20,18 @@ public function chat(Request $request){
|
|||
}
|
||||
|
||||
public function getTicketMessages(Request $request){
|
||||
$messages = Message::where('ticket_id', $request->ticket_id)->orderBy('id', 'asc')->get();
|
||||
return MessageResource::collection($messages);
|
||||
if(Ticket::find($request->ticket_id)){
|
||||
$messages = Message::where('ticket_id', $request->ticket_id)->orderBy('id', 'asc')->get();
|
||||
return MessageResource::collection($messages);
|
||||
}
|
||||
return response()->json([
|
||||
"message" => "There is no ticket id with value: " . $request->ticket_id,
|
||||
"errors" => [
|
||||
"ticket_id" => [
|
||||
"There is no ticket id with value: " . $request->ticket_id
|
||||
]
|
||||
]
|
||||
], 404);
|
||||
}
|
||||
|
||||
public function postMessage(MessageRequest $request){
|
||||
|
|
@ -29,6 +39,9 @@ public function postMessage(MessageRequest $request){
|
|||
$message = new Message($request->only(['ticket_id', 'content']));
|
||||
$message['is_client'] = true;
|
||||
$message->save();
|
||||
$ticket = Ticket::find($request->ticket_id);
|
||||
$ticket['last_sender'] = 'client';
|
||||
$ticket->save();
|
||||
return MessageResource::make($message);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
|
@ -41,6 +54,9 @@ public function postMessageAdmin(MessageRequest $request){
|
|||
$message = new Message($request->only(['ticket_id', 'content', 'admin_id', 'status_id']));
|
||||
$message['is_client'] = false;
|
||||
$message->save();
|
||||
$ticket = Ticket::find($request->ticket_id);
|
||||
$ticket['last_sender'] = 'admin';
|
||||
$ticket->save();
|
||||
return MessageResource::make($message);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
|
@ -60,6 +76,7 @@ public function postTicket(TicketRequest $request){
|
|||
$ticket['client_id'] = $client->id;
|
||||
$status = Status::where('name', 'LIKE', '%' . 'Open' . '%')->firstOrFail();
|
||||
$ticket['status_id'] = $status->id;
|
||||
$ticket['last_sender'] = 'client';
|
||||
$ticket->save();
|
||||
|
||||
return TicketResource::make($ticket);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@ protected function setupListOperation()
|
|||
'name' => 'status',
|
||||
'type' => 'status',
|
||||
'label' => 'Status'
|
||||
],
|
||||
[
|
||||
'name' => 'last_sender',
|
||||
]
|
||||
]);
|
||||
|
||||
|
|
@ -87,39 +90,47 @@ protected function setupCreateOperation()
|
|||
|
||||
$this->crud->addFields([
|
||||
[
|
||||
'name' => 'title',
|
||||
'type' => 'text',
|
||||
'name' => 'title',
|
||||
'type' => 'text',
|
||||
'label' => 'Title'
|
||||
],
|
||||
[
|
||||
'name' => 'content',
|
||||
'type' => 'textarea',
|
||||
'name' => 'content',
|
||||
'type' => 'textarea',
|
||||
'label' => 'Content'
|
||||
],
|
||||
[
|
||||
'name' => 'client_id',
|
||||
'entity' => 'client',
|
||||
'type' => 'select',
|
||||
'label' => 'Client',
|
||||
'name' => 'client_id',
|
||||
'entity' => 'client',
|
||||
'type' => 'select',
|
||||
'label' => 'Client',
|
||||
'attribute' => 'email',
|
||||
'model' => 'App\Models\Client'
|
||||
'model' => 'App\Models\Client'
|
||||
],
|
||||
[
|
||||
'name' => 'category_id',
|
||||
'entity' => 'category',
|
||||
'type' => 'select',
|
||||
'label' => 'Category',
|
||||
'name' => 'category_id',
|
||||
'entity' => 'category',
|
||||
'type' => 'select',
|
||||
'label' => 'Category',
|
||||
'attribute' => 'name',
|
||||
'model' => 'App\Models\Category'
|
||||
'model' => 'App\Models\Category'
|
||||
],
|
||||
[
|
||||
'name' => 'status_id',
|
||||
'entity' => 'status',
|
||||
'type' => 'select',
|
||||
'label' => 'Status',
|
||||
'name' => 'status_id',
|
||||
'entity' => 'status',
|
||||
'type' => 'select',
|
||||
'label' => 'Status',
|
||||
'attribute' => 'name',
|
||||
'model' => 'App\Models\Status'
|
||||
'model' => 'App\Models\Status'
|
||||
],
|
||||
[
|
||||
'name' => 'last_sender',
|
||||
'label' => 'Last sender',
|
||||
'type' => 'select_from_array',
|
||||
'options' => ['admin' => 'admin', 'client' => 'client'],
|
||||
'allows_null' => false,
|
||||
'default' => 'admin'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ public function toArray($request)
|
|||
'category' => CategoryResource::make($this->category),
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'status' => $this->status->name
|
||||
'status' => $this->status->name,
|
||||
'last_sender' => $this->last_sender
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ class Ticket extends Model
|
|||
'status_id',
|
||||
'title',
|
||||
'content',
|
||||
'category_id'
|
||||
'category_id',
|
||||
'last_sender'
|
||||
];
|
||||
// protected $hidden = [];
|
||||
// protected $dates = [];
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public function up()
|
|||
{
|
||||
Schema::create('messages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id');
|
||||
$table->foreignId('ticket_id')->references('id')->on('tickets')->onDelete('cascade');;
|
||||
$table->boolean('is_client'); //if client diplay as client's message, else display as admin reply
|
||||
$table->string('content');
|
||||
$table->foreignId('admin_id')->nullable();;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table) {
|
||||
$table->enum('last_sender', ['admin', 'client'])->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue