本文整理汇总了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());
});
}
示例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();
});
}
示例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);
}
示例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);
});
}
示例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'));
}
示例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]);
示例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]);
}