-2

I want to return an error message using Sweet alert going through my Laravel controller.

Controller

public function update(TenderRequest $request,$id)
{
    $tender = TenderMaster::findOrFail($id);

    if($request->extend_date < $request->end_date){
    //Return error message here
    }
}

Sweet Alert Function:

error: function (data) {
    var errors = data.responseJSON;
    //console.log(errors.message.errors);
    $.each(errors.errors,function (k,v) {
        Swal.fire({
            title: 'Error!',
            html:
            '<h4><code>' + v + '</code></h4>',
            confirmButtonText: 'Close',
            confirmButtonColor: '#d33',
        })
    });
}
Kerel
  • 636
  • 5
  • 16
Vivek kalanka
  • 43
  • 1
  • 9

3 Answers3

0

You can go back with back() function and add the error as usual:

if($request->extend_date < $request->end_date){
     Alert::error('Error Message', 'Optional Title');
     return redirect()->back();
}
else ...
Berto99
  • 7,767
  • 2
  • 7
  • 22
0

i hop i got you well. you can do this

return response()->with('error','data');
amr degheidy
  • 155
  • 8
0

Try like this...

   return Response::json([('status' => 'success','data'=>'data')]);