当前位置: 首页>>代码示例>>PHP>>正文


PHP Article::published方法代码示例

本文整理汇总了PHP中app\models\Article::published方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::published方法的具体用法?PHP Article::published怎么用?PHP Article::published使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Article的用法示例。


在下文中一共展示了Article::published方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: composeSidebar

 /**
  * Compose the sidebar.
  */
 private function composeSidebar()
 {
     view()->composer('partials.sidebar', function ($view) {
         $view->with('latest', Article::published()->orderBy('id', 'desc')->take(5)->get());
         $view->with('tags', Tag::all());
     });
 }
开发者ID:mattvb91,项目名称:website-laravel,代码行数:10,代码来源:ViewComposerServiceProvider.php

示例2: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     parent::boot($router);
     //$router->model('articles','App\Models\Article');
     $router->bind('articles', function ($id) {
         return Article::published()->findOrFail($id);
     });
     $router->bind('tag', function ($name) {
         return Tag::where('name', $name)->firstOrFail();
     });
 }
开发者ID:ruslankus,项目名称:lavarel-lessons,代码行数:18,代码来源:RouteServiceProvider.php

示例3: getSearch

 public function getSearch(Request $request)
 {
     $search = $request->get('query');
     $articles = Article::published()->join('users', 'users.id', '=', 'articles.user_id')->where(function ($q) use($search) {
         $q->where('title', 'like', '%' . $search . '%')->orWhere(function ($query) use($search) {
             $query->where('users.name', 'like', '%' . $search . '%')->orWhere('users.surname', 'like', '%' . $search . '%')->orWhere(\DB::raw('concat(users.name, \' \', users.surname)'), 'like', '%' . $search . '%');
         })->orWhere(function ($query) use($search) {
             $tag = array_flatten(Tag::where('name', 'like', '%' . $search . '%')->get(['id'])->toArray());
             $articleTagMapper = array_flatten(ArticleTagMapper::whereIn('tag_id', $tag)->distinct()->get(['article_id'])->toArray());
             $query->whereIn('id', $articleTagMapper);
         });
     })->get(['articles.id', 'articles.title']);
     return response()->json($articles);
 }
开发者ID:psiskova,项目名称:blog-academy,代码行数:14,代码来源:SearchController.php

示例4: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @return void
  */
 public function boot()
 {
     parent::boot();
     Route::bind('article', function ($slug) {
         if (!Auth::user()) {
             return Article::published()->slug($slug)->first();
         }
         return Article::where('slug', $slug)->first() ?: Article::findOrFail((int) $slug);
     });
     Route::bind('tag', function ($slug) {
         if (!Auth::user()) {
             return Tag::slug($slug)->first();
         }
         return Tag::where('slug', $slug)->first() ?: Tag::findOrFail((int) $slug);
     });
     Route::bind('page', function ($id) {
         return Page::find($id);
     });
 }
开发者ID:mattvb91,项目名称:website-laravel,代码行数:24,代码来源:RouteServiceProvider.php

示例5: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $articles = Article::published()->orderBy('id', 'desc')->paginate(5);
     return view('article.index', compact('articles'));
 }
开发者ID:mattvb91,项目名称:website-laravel,代码行数:10,代码来源:ArticleController.php

示例6: collect

        });
    }
    $articles = $articles->orderBy('articles.updated_at', 'desc')->select(DB::raw('articles.id, articles.text, articles.title, articles.slug, articles.user_id, articles.updated_at'))->paginate(5);
    $topUsers = Article::published()->limit(3)->groupBy('user_id')->orderByRaw('count(user_id) DESC')->get();
    $bestUsers = User::all();
    $bestUsers = collect($bestUsers->sortByDesc(function ($user) {
        return $user->average_rating;
    }))->reject(function ($user) {
        return $user->average_rating == 0;
    });
    $bestUsers = $bestUsers->slice(0, 3);
    return view('index', ['articles' => $articles, 'topUsers' => $topUsers, 'bestUsers' => $bestUsers, 'search' => $search]);
});
Route::get('/about-us', function () {
    $users = User::where('role', '=', User::TEACHER_ROLE)->get();
    $articlesCount = Article::published()->count();
    $usersCount = User::count();
    $commentsCount = \App\Models\Discussion::count();
    return view('aboutus', ['users' => $users, 'articlesCount' => $articlesCount, 'usersCount' => $usersCount, 'commentsCount' => $commentsCount]);
});
Route::get('/faq', function () {
    return view('faq');
});
Route::get('/rules', function () {
    return view('rules');
});
Route::get('/migrate/{id}', function () {
    Artisan::call('migrate', ['--force' => true]);
})->where('id', 'lesna_jahoda');
Route::get('/seed/{id}', function () {
    Artisan::call('db:seed', ['--force' => true]);
开发者ID:psiskova,项目名称:blog-academy,代码行数:31,代码来源:routes.php

示例7: getGrading

    public function getGrading($id = null)
    {
        if (!$id && Auth::check()) {
            $id = Auth::user()->slug;
        }
        $user = User::findBySlugOrIdOrFail($id);
        $course = $user->course;
        if ($course) {
            $course_id = $course->id;
            if ($user->hasRole(User::STUDENT_ROLE)) {
                $unratedArticles = $user->articles()->published()->unrated($course_id)->get();
                $ratedArticles = $user->articles()->published()->rated($course_id)->get();
            } else {
                $unratedArticles = Article::published()->unrated($course_id)->get();
                $ratedArticles = DB::select(DB::raw('
                    select
                      *
                    from (
                        select
                            users.id as user_id,
                            avg(ratings.rating) as rating
                        from
                            articles,
                            participants,
                            courses,
                            tasks,
                            ratings,
                            users
                        where
                            users.id = articles.user_id and
                            courses.id = ' . $course_id . ' and
                            tasks.course_id = courses.id and
		                    participants.user_id = users.id and
                            participants.course_id = courses.id and
                            articles.task_id = tasks.id and
                            ratings.text <> \'\' and
                            ratings.article_id = articles.id
                        having
                            avg(ratings.rating) > 0
                        union
                            select
                              participants.user_id as user_id,
                              0 as rating
                            from
                              participants
                            where
                              participants.course_id =  ' . $course_id . ' and
                              participants.state = 2
                    ) t
                    group by
                      user_id'));
            }
        } else {
            $unratedArticles = [];
            $ratedArticles = [];
        }
        return view('users.grading', ['user' => $user, 'unratedArticles' => $unratedArticles, 'ratedArticles' => $ratedArticles]);
    }
开发者ID:psiskova,项目名称:blog-academy,代码行数:58,代码来源:UserController.php


注:本文中的app\models\Article::published方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。