本文整理汇总了PHP中app\Article::published方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::published方法的具体用法?PHP Article::published怎么用?PHP Article::published使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::published方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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->bind('articles', function ($id) {
return Article::published()->findOrFail($id);
});
}
示例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->bind('articles', function ($id) {
$article = Article::findOrFail($id);
// If the owner return all articles else return only published.
if (Auth::user() && $article->user_id === Auth::user()->id) {
$articles = Article::findOrFail($id);
} else {
$articles = Article::published()->findOrFail($id);
}
return $articles;
});
$router->bind('questions', function ($id) {
return Question::findOrFail($id);
});
$router->bind('answers', function ($id) {
return Answer::findOrFail($id);
});
$router->bind('tags', function ($name) {
return Tag::where('name', $name)->firstOrFail();
});
$router->bind('users', function ($id) {
return User::findOrFail($id);
});
}
示例3: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
parent::boot($router);
/**
* Binding the model
*/
// $router->model('articles', 'App\Article');
/**
* Optional custom bind
*/
$router->bind('articles', function ($id) {
/**
* Show only the published articles
*/
return \App\Article::published()->findOrFail($id);
});
// $router->model('tags', 'App\Tag');
$router->bind('tags', function ($name) {
/**
* Show only the related same tag by name
*/
return \App\Tag::where('name', $name)->firstOrFail();
});
}
示例4: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
parent::boot($router);
/*Route::model*/
/**
* Route model binding altering default logic
* $router->bind('articles',function($id){
* return \App\Article::published()->findOrFail($id);
* });
*/
/*Using wildcard*/
/*$router->model('articles','App\Article');*/
$router->bind('articles', function ($id) {
return \App\Article::published()->findOrFail($id);
});
$router->bind('rates', function ($id) {
return \App\Rate::where('id', $id)->firstOrFail();
});
$router->bind('customers', function ($id) {
return \App\Customer::where('id', $id)->firstOrFail();
});
$router->bind('tags', function ($name) {
return \App\Tag::where('name', $name)->firstOrFail();
});
$router->bind('motherboards', function ($name) {
return \App\Motherboard::where('name', $name)->firstOrFail();
});
}
示例5: getCoursesInCategory
public function getCoursesInCategory($slug)
{
$articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get();
$category = Category::where('slug', $slug)->first();
$courses = Course::published()->where('category_id', $category->id)->get();
return view('courses.index', ['courses' => $courses, 'page_id' => $slug, 'category' => $category, 'latest_articles' => $articles]);
}
示例6: show
public function show($slug)
{
$page = Page::where('slug', $slug)->first();
$courses = Course::published()->hasCategory()->orderBy('created_at', 'desc')->take(4)->get();
$articles = Article::published()->orderBy('published_at', 'desc')->take(2)->get();
return view('pages.show', ['page' => $page, 'latest_courses' => $courses, 'latest_articles' => $articles]);
}
示例7: 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->bind('articles', function ($id) {
return \App\Article::published()->findOrFail($id);
});
$router->model('articles', 'App\\Article');
}
示例8: 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->bind('articles', function ($id) {
return \Route::currentRouteName() == "articles.edit" ? \App\Article::findOrFail($id) : \App\Article::published()->findOrFail($id);
});
$router->bind('tags', function ($name) {
return \App\Tag::where('name', $name)->firstOrFail();
});
}
示例9: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
$router->bind('articles', function ($id) {
return Article::published()->findOrFail($id);
});
$router->bind('tags', function ($tags) {
return Tag::where('name', $tags)->first();
});
parent::boot($router);
}
示例10: 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->bind('articles', function ($id) {
return \App\Article::published()->findOrFail($id);
});
$router->bind('tags', function ($name) {
return \App\tag::where('name', $name)->firstOrFail();
});
}
示例11: edit
public function edit($id)
{
if (Auth::user()->name === 'Penna') {
$article = Article::published()->findOrFail($id);
if (Auth::user()->id == $article->user_id) {
return view('edit', compact('article'));
} else {
return redirect('/');
}
}
}
示例12: 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\Article');
//\Illuminate\Support\Facades\Route::model('articles', 'App\Article');
$router->bind('articles', function ($id) {
return \App\Article::published()->findOrFail($id);
//return \App\Article::findOrFail($id);
});
}
示例13: composeSidebar
private function composeSidebar()
{
view()->composer('blog.partials.side', function ($view) {
$allCategories = \App\Category::getSortedCategories();
$NewestArticles = \App\Article::published()->orderBy('updated_at', 'desc')->take(10)->get();
$view->with(compact('allCategories', 'NewestArticles'));
});
view()->composer('home.partials.side', function ($view) {
$NewestArticles = \App\Article::published()->orderBy('updated_at', 'desc')->take(10)->get();
$view->with(compact('NewestArticles'));
});
}
示例14: 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\Article');
/**
*Tuong tu cho ham ben tren
*/
$router->bind('articles', function ($id) {
return \App\Article::published()->findOrFail($id);
});
$router->bind('tag', function ($name) {
return \App\Tag::where('name', $name)->firstOrFail();
});
}
示例15: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
/**
* Bind the wildcard 'articles' with the model App\Article for use in Route Model Binding.
*/
//$router->model('articles', 'App\Article');
$router->bind('articles', function ($id) {
return \App\Article::published()->findOrFail($id);
});
$router->bind('tags', function ($name) {
return \App\Tag::where('name', $name)->firstOrFail();
});
}