/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $username = \Request::server('PHP_AUTH_USER', 'sampleuser'); $response = []; $type = $request->input('type', ''); $id = $request->input('id', ''); $model = null; switch ($type) { case 'Content': $model = Content::find($request->input('id')); break; case 'Dvd': $model = Dvd::find($request->input('id')); break; case 'Dvdseries': $model = Dvdseries::find($request->input('id')); break; case 'Model': $model = Model::find($request->input('id')); break; } if ($username && $id && $model) { if (Favorite::ofUsername($username)->hasFavorite($type, $id)->count()) { $response['success'] = false; $response['message'] = 'Already in your favorites.'; } else { $fav = new Favorite(); $fav->username = $username; $model->favorites()->save($fav); $response['success'] = true; $response['message'] = 'Successfully added to your favorites.'; } } return \Response::json($response); }
/** * Create a new job instance. * * @return void */ public function __construct($id) { $this->content = Content::find($id); $this->username = \Request::server('PHP_AUTH_USER'); $referer = \Request::server('HTTP_REFERER'); $this->referrer = $referer ? $referer : ''; }
/** * Create a new job instance. * * @return void */ public function __construct($id, $rating, $username = '') { $this->content = Content::find($id); $this->rating = $rating; $this->username = '******'; //$username; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $username = \Request::server('PHP_AUTH_USER', 'sampleuser'); $response = []; $content_id = $request->input('content_id', 0); $type = $request->input('type', ''); $current_list = $request->input('current_list', ''); $new_list_name = $request->input('new_list_name', ''); $list_visibility = $request->input('list_visibility', ''); $content = Content::find($content_id); if (!$username || !$content) { return \Response::json(['success' => false, 'message' => 'Cannot save playlist.']); } if ($type == 'playlist') { $playlist = Playlist::ofUsername($username)->find($current_list); if ($playlist) { if ($playlist->contents->contains($content->id)) { $response['success'] = false; $response['message'] = $content->title . ' already in playlist ' . $playlist->name . '.'; } else { $playlist->contents()->attach($content->id); $response['success'] = true; $response['message'] = $content->title . ' successfully added in playlist ' . $playlist->name . '.'; } } else { $response['success'] = false; $response['message'] = 'Please select a playlist.'; } } if ($type == 'new-list') { $playlist = new Playlist(); $playlist->username = $username; $playlist->name = $new_list_name; $playlist->visibility = $list_visibility; $playlist->save(); $playlist->contents()->attach($content->id); $response['success'] = true; $response['message'] = $new_list_name . ' successfully created!'; } return \Response::json($response); }
public function comment() { $id = \Request::input('id', 0); $username = \Request::input('username', ''); $message = \Request::input('message', ''); $content = Content::find($id); if ($content && $message != '') { $comment = new Comment(); $comment->username = \Request::input('username'); $comment->message = \Request::input('message'); $comment->content()->associate($content); $comment->save(); } $data['content'] = $content; return Theme::view('content.comments_list', $data); }