public function openedForCurrentUser($id) { if (!auth()->user()) { return 0; } if (self::find($id)->user_id == auth()->user()->id) { return 1; } return UnlokedTerrain::where('user_id', auth()->user()->id)->where('terrain_id', $id)->count(); }
public function open() { $id = Input::get('id'); if ($id == false) { // return doar credit (pt reresh) return success(['credit' => auth()->user()->credit], 'Credit actualizat. Incercati sa deschideti contactul proprietarului din nou. Aveti:' . auth()->user()->credit . ' RON.'); } if (auth()->user()->credit <= config('credit.pret_cumparator')) { return error('Nu aveti suficient credit', ['credit' => auth()->user()->credit]); } else { User::credit(-config('credit.pret_cumparator')); UnlokedTerrain::create(['user_id' => auth()->user()->id, 'terrain_id' => $id]); return success(['success' => 'Am deschis', 'credit' => auth()->user()->credit, 'telefon' => Terrain::find($id)->telefon]); } }