incorporeal incorporeal - 9 months ago 33
PHP Question

Laravel: Script message is not showing

i want to delete a row from my database after clicking a href link. It is working fine. But after completing deletion i want show a message to the user. but it is not showing. my if condition is also not working...it is showing

Object of class Illuminate\Support\Collection could not be converted to int

my code is here:

public function postDelete($booked_by)
{
$user_id = Auth::user()->id;
$booking_id = DB::table('bookings')
->select('id')
->where('booked_by', '=', $user_id)
->get();

// dd($booking_id);

if($user_id == $booking_id)
{
$user = DB::table('bookings')
->where('booked_by', '=', $user_id)
->delete();

return back();
$message = "Your booking is canceled";
echo "<script type='text/javascript'>alert('$message'); </script>";

else
{
$message = "You can't delete which is booked by others";
echo "<script type='text/javascript'>alert('$message');</script>";}


return back();


}


what should i change?

Answer Source

Please use Flash Message in this case:

https://laravel.com/docs/5.4/session#flash-data

If you use alert message it's really dangerous with XSS bugs.