コード例 #1
0
 public function status($id)
 {
     $post = Post::where('id', $id)->first();
     if ($post['post_status'] == '0') {
         Post::Where('id', $id)->update(['post_status' => '1']);
         $status = 'active';
     } elseif ($post['post_status'] == '1') {
         Post::Where('id', $id)->update(['post_status' => '0']);
         $status = 'inactive';
     } else {
         return Response::json(['status' => 'error']);
     }
     return Response::json(['status' => $status]);
 }
コード例 #2
0
ファイル: routes.php プロジェクト: aboustayyef/ysn
Route::get('updateme/{id}', function ($id) {
    $response = ['posts' => App\Post::numberOfPostsSinceId($id)];
    return response()->json($response);
});
Route::get('dumper', function () {
    $getter = new \App\Getters\LebaneseBlogsGetter();
    $post = $getter->getList()[0];
    $post = (new \App\Transformers\LebaneseBlogsTransformer($post))->get();
    return $post;
});
Route::get('/{provider?}', function ($provider = null) {
    if ($provider) {
        // make sure the provider supported
        if (!in_array($provider, ['facebook', 'youtube', 'instagram', 'lebaneseblogs', 'twitter'])) {
            return response('page does not exist', 404);
        }
        // prepare posts. Cache if no cache
        $cacheRef = $provider . '__lastFiftyPosts';
        if (!\Cache::has($cacheRef)) {
            \Cache::put($cacheRef, \App\Post::Where('provider', $provider)->orderBy('date_published', 'DESC')->take(50)->get(), 3);
        }
        $posts = \Cache::get($cacheRef);
    } else {
        // prepare posts. Cache if no cache
        if (!\Cache::has('lastFiftyPosts')) {
            \Cache::put('lastFiftyPosts', \App\Post::orderBy('date_published', 'DESC')->take(50)->get(), 3);
        }
        $posts = \Cache::get('lastFiftyPosts');
    }
    return view('layout')->with(['posts' => $posts, 'provider' => $provider]);
});