/** * Authorize the upload action of a picture album * see the route list for details * * @param $model * @param $model_id * @param $id * * @return bool */ private function _authorize($model, $model_id, $id) { switch ($model) { case 'user': if ($id != 'new') { $this->album = Album::where('id', $id)->first(); session(['album_id' => null]); } else { if (session('album_id') && session('album_id') != null) { $this->album = Album::where('id', session('album_id'))->first(); } else { $this->makeNewAlbum(); Auth::user()->albums()->save($this->album); $this->album->update(['user_id' => Auth::id()]); } } break; case 'article': $this->article = Article::whereId($id)->first(); if (!($this->album = Album::where('albumable_id', $id)->get()->first())) { $this->makeNewAlbum(); $this->article->albums()->save($this->album); } break; case 'profession': $this->profession = Profession::whereId($id)->first(); if (!($this->album = Album::where('albumable_id', $id)->get()->first())) { $this->makeNewAlbum(); $this->profession->albums()->save($this->album); } break; case 'site': $this->site = Site::whereId($model_id)->first(); if (!($this->album = Album::where('id', $id)->first())) { if (!$this->site->albums->last()) { $this->makeNewAlbum(); $this->site->albums()->save($this->site); } } break; case 'classified': $this->classified = Classified::whereId($id)->first(); if (!($this->classified = Album::where('albumable_id', $id)->get()->first())) { $this->makeNewAlbum(); $this->classified->albums()->save($this->album); } break; } //session(['album_id' => $this->album->id]); return true; }