预言 / 画布
一个Laravel发布平台
Requires
- php: ^7.3|^8.0
- ext-json: *
- laravel/framework: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- laravel/legacy-factories: ^1.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0
This package is auto-updated.
Last update: 2024-09-07 00:32:38 UTC
README
简介
Canvas是一个完全开源的包,可以扩展您现有的Laravel应用程序,并在几分钟内让您拥有一个博客。除了无干扰的写作体验外,您还可以查看您的内容的月度趋势,了解读者流量等方面!
系统要求
- PHP >= 7.3
- Laravel >= 6.0
- Laravel支持的五种数据库之一
安装
您可以使用Composer将Canvas安装到您的Laravel项目中
composer require austintoddj/canvas
使用canvas:install
Artisan命令发布资产和主要配置文件
php artisan canvas:install
使用storage:link
Artisan命令创建符号链接,以确保文件上传可以从网络公开访问
php artisan storage:link
配置
在发布Canvas的资产后,主要配置文件将位于config/canvas.php
。此文件允许您自定义应用程序使用此包的各种方面。
Canvas默认在/canvas
处公开其UI。这可以通过更新path
或domain
选项来更改
/* |-------------------------------------------------------------------------- | Base Domain |-------------------------------------------------------------------------- | | This is the subdomain where Canvas will be accessible from. If the | domain is set to null, Canvas will reside under the defined base | path below. Otherwise, this will be used as the subdomain. | */ 'domain' => env('CANVAS_DOMAIN', null), /* |-------------------------------------------------------------------------- | Base Path |-------------------------------------------------------------------------- | | This is the URI where Canvas will be accessible from. If the path | is set to null, Canvas will reside under the same path name as | the application. Otherwise, this is used as the base path. | */ 'path' => env('CANVAS_PATH_NAME', 'canvas'),
有时,您可能希望在访问Canvas时应用自定义角色或权限。您可以在其中创建和附加任何额外的中间件
/* |-------------------------------------------------------------------------- | Route Middleware |-------------------------------------------------------------------------- | | These middleware will be attached to every route in Canvas, giving you | the chance to add your own middleware to this list or change any of | the existing middleware. Or, you can simply stick with the list. | */ 'middleware' => [ 'web', ],
Canvas使用存储磁盘进行媒体上传。您可以在此处配置不同的文件系统选项
/* |-------------------------------------------------------------------------- | Storage |-------------------------------------------------------------------------- | | This is the storage disk Canvas will use to put file uploads. You may | use any of the disks defined in the config/filesystems.php file and | you may also change the maximum upload size from its 3MB default. | */ 'storage_disk' => env('CANVAS_STORAGE_DISK', 'local'), 'storage_path' => env('CANVAS_STORAGE_PATH', 'public/canvas'), 'upload_filesize' => env('CANVAS_UPLOAD_FILESIZE', 3145728),
角色 & 权限
Canvas自带3个预定义角色
- 贡献者(可以写和管理自己的帖子,但不能发布)
- 编辑器(可以发布和管理帖子,包括其他用户的帖子)
- 管理员(可以做任何事情并看到一切)
当您安装Canvas的新版本时,将自动设置一个默认管理员用户。从那里,您可以对用户执行任何基本CRUD操作,以及分配他们的各种角色。
Canvas UI
想要一个美丽的、受Medium.com启发的前端吗?使用canvas:ui
Artisan命令安装脚手架
php artisan canvas:ui
在生成前端脚手架后,您的package.json
文件将包括安装和编译所需的所有依赖项
# Using NPM npm install npm run dev # Using Yarn yarn yarn dev
就是这样!您可以通过/canvas-ui
导航并亲自检查。您可以随意修改任何您喜欢的方面。
Unsplash集成
想要访问整个Unsplash库吗?在https://unsplash.com/oauth/applications上设置一个新应用程序,获取您的访问密钥,并更新config/canvas.php
/* |-------------------------------------------------------------------------- | Unsplash Integration |-------------------------------------------------------------------------- | | Visit https://unsplash.com/oauth/applications to create a new Unsplash | app. Use the confidential Access Key given to you to integrate with | the API. Note that demo apps are limited to 50 requests per hour. | */ 'unsplash' => [ 'access_key' => env('CANVAS_UNSPLASH_ACCESS_KEY'), ]
电子邮件通知
想要每周摘要吗?Canvas允许用户接收他们所创作的内容的每周摘要。一旦您的应用程序已配置为发送邮件,请更新config/canvas.php
/* |-------------------------------------------------------------------------- | E-Mail Notifications |-------------------------------------------------------------------------- | | This option controls e-mail notifications that will be sent via the | default application mail driver. A default option is provided to | support the notification system as an opt-in feature. | | */ 'mail' => [ 'enabled' => env('CANVAS_MAIL_ENABLED', false), ]
由于此功能运行在Laravel的调度器上,您需要将以下cron条目添加到您的服务器
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
API
安装Canvas UI将是获得前端界面以显示数据的最高效方法。然而,许多用户会选择手动创建此界面,因为这为他们提供了设计美学的灵活性。
使用published
作用域可以仅检索过去有发布日期的文章
Canvas\Models\Post::published()->get()
您也可以使用draft
作用域来检索其逆
Canvas\Models\Post::draft()->get()
要返回单个文章,您可能需要通过给定的别名找到它,以及包含相关的实体,例如
$post = Canvas\Models\Post::with('user', 'tags', 'topic')->firstWhere('slug', $slug);
重要: 在返回文章的同一种方法中,请确保触发
PostViewed
事件,否则将无法记录视图/访问。
event(new Canvas\Events\PostViewed($post));
您可以通过给定的别名找到标签
Canvas\Models\Tag::with('posts')->firstWhere('slug', $slug);
类似的查询可以用于主题
Canvas\Models\Topic::with('posts')->firstWhere('slug', $slug);
可以通过id
、username
或email
检索用户
$user = Canvas\Models\User::find($id); $user = Canvas\Models\User::firstWhere('username', $username); $user = Canvas\Models\User::firstWhere('email', $email);
此外,您可以返回与相关主题关联的用户发布的文章
$user->posts()->published()->with('topic')
更新
Canvas遵循语义化版本控制,并以MAJOR.MINOR.PATCH
数字递增版本。
- 主版本将包含破坏性更改,因此请遵循升级指南以获取逐步说明
- 次要版本和修补程序版本不应包含破坏性更改,因此您可以安全地按照以下步骤更新包
您可以使用composer更新Canvas安装
composer update
使用canvas:migrate
Artisan命令运行任何新的迁移
php artisan canvas:migrate
使用canvas:publish
Artisan命令重新发布资产
php artisan canvas:publish
为了保持资产最新并避免未来更新中出现的问题,您可以将canvas:publish
命令添加到应用程序的composer.json
文件中的post-update-cmd
脚本中
{ "scripts": { "post-update-cmd": [ "@php artisan canvas:publish --ansi" ] } }
贡献
测试
使用以下命令运行测试
composer test
故障排除
如果您遇到问题,请随意打开新问题或检查讨论论坛,看看是否有人遇到类似的问题。
许可
Canvas是开源软件,采用MIT许可。