<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Favoritos;
use Auth;


class FavoritosController extends Controller
{
    public function index(){
        $favoritos = Favoritos::where('user_id',Auth::user()->id)->paginate(16);
        return view('user.favoritos',compact('favoritos'));
    }

    public function favoritos($id){

    	$favoritos = Favoritos::where('user_id',Auth::user()->id)->where('id_hotel',$id)->get();

    	if ($favoritos->count() > 0) {
    		$favoritos = $favoritos->first();
    		$favoritos->delete();
    	}else{
    		$favoritos = new Favoritos();
    		$favoritos->user_id = Auth::user()->id;
    		$favoritos->id_hotel = $id;
    		$favoritos->save();
    	}
    	return redirect()->back();
    }
}
