skip to Main Content

I want to submit a form using .on('submit', function (event) I get this error and can’t figure out why. the error shows for all these tickets route not just the example I am posting.

Here is the route part:

Route::post('tickets/update', [SupportTicketController::class, 'update'])->name('tickets.update');
Route::resource('tickets', SupportTicketController::class)->except(['destroy', 'create', 'update']);
Route::post('tickets/{ticket}/assigned', [EmployeeAssignedController::class, 'employeeTicketAssigned'])->name('tickets.assigned');
Route::get('tickets/{id}/delete', [SupportTicketController::class, 'destroy'])->name('tickets.destroy');
Route::get('tickets/download/{id}', [SupportTicketController::class, 'download'])->name('tickets.downloadTicket');
Route::post('tickets/delete/selected', [SupportTicketController::class, 'delete_by_selection'])->name('mass_delete_tickets');
Route::post('tickets/{ticket}/comments', [SupportTicketCommentController::class, 'index'])->name('ticket_comments.index');
Route::post('tickets/store_comments/{ticket}', [SupportTicketCommentController::class, 'store'])->name('ticket_comments.store');
Route::get('tickets/{id}/delete_comments', [SupportTicketCommentController::class, 'destroy'])->name('ticket_comments.destroy');
Route::post('tickets/{ticket}/details', [SupportTicketController::class, 'detailsStore'])->name('ticket_details.store');
Route::post('tickets/{ticket}/notes', [SupportTicketController::class, 'notesStore'])->name('ticket_notes.store');

view javascript example:

$('#assigned_form').on('submit', function (event) {
event.preventDefault();

$.ajax({
    url: "{{ route('tickets.assigned',$ticket) }}",
    method: "post",
    data: new FormData(this),
    contentType: false,
    cache: false,
    processData: false,
    dataType: "json",
    success: function (data) {
        let html = '';
        if (data.errors) {
            html = '<div class="alert alert-danger">';
            for (let count = 0; count < data.errors.length; count++) {
                html += '<p>' + data.errors[count] + '</p>';
            }
            html += '</div>';
        }
        if (data.success) {
            html = '<div class="alert alert-success">' + data.success + '</div>';
        }
        $('#assigned_result').html(html).slideDown(300).delay(500).slideUp(300);
    }
})

});

and this is the route is calling:

public function employeeTicketAssigned(Request $request, SupportTicket $ticket)
{
$role = Role::find(Auth::user()->role_id);
if($role->hasPermissionTo('assign-ticket'))
{
    $employees = $request->input('employee_id');
    $ticket->assignedEmployees()->sync($employees);
    $notificable = User::where('role_id', 1)
        ->orWhere('id', $ticket->employee->id)
        ->orWhere('id', $ticket->customer->id)
        ->orwhereIntegerInRaw('id', $employees)
        ->get();
    Notification::send($notificable, new TicketAssignedNotification($ticket));

    return response()->json(['success' => __('تم إدخال البيانات بنجاح')]);
}

return response()->json(['success' => __('غير مصرح لك')]);
}

3

Answers


  1. Seem you didn’t pass second argument for route.

    For example

    Route::get('/post/{post}/comment/{comment}', function () {
        //
    })->name('comment.show');
    
    route('comment.show', ['post' => 1, 'comment' => 3]);
    

    In your case, it could be

    url: "{{ route('tickets.assigned', ['ticket' => $ticket]) }}",
    
    Login or Signup to reply.
  2. use below command in cmd
    php artisan config:cache
    php artisan config:clear

    Login or Signup to reply.
  3. Maybe the form data is not being serialized correctly

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search