Tuesday, March 14, 2017

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 ?



via incorporeal

Advertisement