本文整理汇总了PHP中app\models\Category::getCategoriesByPublish方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::getCategoriesByPublish方法的具体用法?PHP Category::getCategoriesByPublish怎么用?PHP Category::getCategoriesByPublish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::getCategoriesByPublish方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$favicon = Settings::getSettings()['favicon'];
$logo = Settings::getSettings()['logo'];
$parent_categories = Category::getCategoriesByPublish(1, 0, 1);
View::share('favicon', $favicon);
View::share('logo', $logo);
View::share('parent_categories', $parent_categories);
}
示例2: edit
/**
* Edit post
*
* @param Request $request
* @param int $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function edit(Request $request, $id = 0)
{
$post = Post::getPostById($id);
if (empty($post)) {
return redirect()->back();
} else {
if ($request->isMethod("post")) {
$rules = ["title" => "required", "alias" => "required|unique:posts,alias," . $id, "content" => "required", 'image' => 'mimes:jpeg,jpg,png'];
Validator::make($request->all(), $rules)->validate();
$post->title = $request->input("title");
$post->alias = $request->input("alias");
$post->content = $request->input("content");
$post->meta_keys = $request->input("meta_keys");
$post->meta_desc = $request->input("meta_desc");
if (!empty($request->file("image"))) {
if (!empty($post->image)) {
if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) {
Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image);
}
}
$generated_string = str_random(32);
$file = $request->file("image")->store('uploads');
$new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
Storage::move($file, 'uploads/' . $new_file);
$img = Image::make($request->file('image'));
$img->crop(200, 200);
$img->save(storage_path('app/public/uploads/' . $new_file));
$img = Image::make($request->file('image'));
$img->resize(600, 315);
$img->save(storage_path('app/public/uploads/fb-' . $new_file));
$post->image = $new_file;
}
if ($request->has("category")) {
$post->category_id = $request->input("category");
}
$post->publish = $request->has("publish");
$post->save();
$new_tags = [];
if ($request->has("tags")) {
$tags = $request->input("tags");
foreach ($tags as $tag) {
array_push($new_tags, $tag);
}
}
$post->tags()->sync($new_tags);
return redirect()->route('posts');
} else {
$categories = Category::getCategoriesByPublish();
$tags = Tag::getTags();
return view("site.post.edit", compact("post", "categories", "tags"));
}
}
}