austintoddj / canvas
A Laravel publishing platform
Fund package maintenance!
austintoddj
Installs: 76 479
Dependents: 1
Suggesters: 0
Security: 2
Stars: 3 258
Watchers: 91
Forks: 521
Open Issues: 30
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
- dev-master
- v6.0.54
- v6.0.53
- v6.0.52
- v6.0.51
- v6.0.50
- v6.0.49
- v6.0.48
- v6.0.47
- v6.0.46
- v6.0.45
- v6.0.44
- v6.0.43
- v6.0.42
- v6.0.41
- v6.0.40
- v6.0.39
- v6.0.38
- v6.0.37
- v6.0.36
- v6.0.35
- v6.0.34
- v6.0.33
- v6.0.32
- v6.0.31
- v6.0.30
- v6.0.29
- v6.0.28
- v6.0.27
- v6.0.26
- v6.0.25
- v6.0.24
- v6.0.23
- v6.0.22
- v6.0.21
- v6.0.20
- v6.0.19
- v6.0.18
- v6.0.17
- v6.0.16
- v6.0.15
- v6.0.14
- v6.0.13
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v5.4.1
- v5.4.0
- v5.3.11
- v5.3.10
- v5.3.9
- v5.3.8
- v5.3.7
- v5.3.6
- v5.3.5
- v5.3.4
- v5.3.3
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.0
- v5.1.1
- v5.1.0
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.2.9
- v4.2.8
- v4.2.7
- v4.2.6
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.39
- v4.1.38
- v4.1.37
- v4.1.36
- v4.1.35
- v4.1.34
- v4.1.33
- v4.1.32
- v4.1.31
- v4.1.30
- v4.1.29
- v4.1.28
- v4.1.27
- v4.1.26
- v4.1.25
- v4.1.24
- v4.1.23
- v4.1.22
- v4.1.21
- v4.1.20
- v4.1.19
- v4.1.18
- v4.1.17
- v4.1.16
- v4.1.15
- v4.1.14
- v4.1.13
- v4.1.12
- v4.1.11
- v4.1.10
- v4.1.9
- v4.1.8
- v4.1.7
- v4.1.6
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.4.5
- v3.4.4
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.4
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.0
- v2.1.17
- v2.1.16
- v2.1.15
- v2.1.14
- v2.1.13
- v2.1.12
- v2.1.11
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0
- dev-develop
- dev-dependabot/composer/orchestra/testbench-8.21.1
- dev-dependabot/composer/phpunit/phpunit-10.5.9
- dev-dependabot/composer/laravel/framework-10.42.0
- dev-dependabot/npm_and_yarn/eslint-plugin-vue-9.20.1
- dev-dependabot/npm_and_yarn/vue-3.4.15
- dev-dependabot/npm_and_yarn/vue-loader-17.4.2
- dev-dependabot/npm_and_yarn/unsplash-js-7.0.19
- dev-dependabot/composer/mockery/mockery-1.6.7
- dev-dependabot/npm_and_yarn/eslint-plugin-sort-imports-es6-autofix-0.6.0
This package is auto-updated.
Last update: 2024-11-12 21:15:21 UTC
README
Introduction
Canvas is a fully open source package to extend your existing Laravel application and get you up-and-running with a blog in just a few minutes. In addition to a distraction-free writing experience, you can view monthly trends on your content, get insights into reader traffic and more!
System Requirements
- PHP >= 7.3
- Laravel >= 6.0
- One of the five supported databases by Laravel
Installation
You may use composer to install Canvas into your Laravel project:
composer require austintoddj/canvas
Publish the assets and primary configuration file using the canvas:install
Artisan command:
php artisan canvas:install
Create a symbolic link to ensure file uploads are publicly accessible from the web using the storage:link
Artisan command:
php artisan storage:link
Configuration
After publishing Canvas's assets, a primary configuration file will be located at config/canvas.php
. This file allows you to customize various aspects of how your application uses the package.
Canvas exposes its UI at /canvas
by default. This can be changed by updating either the path
or domain
option:
/* |-------------------------------------------------------------------------- | 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'),
Sometimes, you may want to apply custom roles or permissions when accessing Canvas. You can create and attach any additional middleware here:
/* |-------------------------------------------------------------------------- | 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 uses the storage disk for media uploads. You may configure the different filesystem options here:
/* |-------------------------------------------------------------------------- | 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),
Roles & Permissions
Canvas comes with 3 pre-defined roles out-of-the-box:
- Contributor (A user who can write and manage their own posts but cannot publish them)
- Editor (A user who can publish and manage posts including the posts of other users)
- Admin (A user who can do everything and see everything)
When you install a fresh version of Canvas, you'll have a default admin user set up automatically. From there, you can perform any basic CRUD actions on users, as well as assign their various roles.
Canvas UI
Want a beautiful, Medium.com-inspired frontend? Use the canvas:ui
Artisan command to install the scaffolding:
php artisan canvas:ui
After generating the frontend scaffolding, your package.json
file will include the necessary dependencies to install and compile:
# Using NPM npm install npm run dev # Using Yarn yarn yarn dev
That's it! You can navigate to /canvas-ui
and check it out for yourself. You're free to modify any aspect of it
that you'd like.
Unsplash Integration
Want access to the entire Unsplash library? Set up a new application at https://unsplash.com/oauth/applications, grab your access key, and update 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'), ]
E-mail Notifications
Want a weekly summary? Canvas allows users to receive a weekly digest of their authored content. Once your application is configured for sending mail, update 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), ]
Since this feature runs on Laravel's Scheduler, you'll need to add the following cron entry to your server:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
API
Installing Canvas UI will be the most efficient way to get up and running with a frontend interface to display your data. However many users will opt for creating this by hand since it gives flexibility to their design aesthetic.
Using the published
scope will allow you to only retrieve posts that have a published date in the past:
Canvas\Models\Post::published()->get()
You can also retrieve the inverse with a draft
scope:
Canvas\Models\Post::draft()->get()
To return a single post, you'll likely want to find it by a given slug, as well as include related entities such as:
$post = Canvas\Models\Post::with('user', 'tags', 'topic')->firstWhere('slug', $slug);
Important: In the same method that returns a post, make sure you fire the
PostViewed
event, or else a view/visit will not be recorded.
event(new Canvas\Events\PostViewed($post));
You can find a tag by a given slug:
Canvas\Models\Tag::with('posts')->firstWhere('slug', $slug);
And a similar query can be used for a topic:
Canvas\Models\Topic::with('posts')->firstWhere('slug', $slug);
Users can be retrieved by their id
, username
, or email
:
$user = Canvas\Models\User::find($id); $user = Canvas\Models\User::firstWhere('username', $username); $user = Canvas\Models\User::firstWhere('email', $email);
Additionally, you can return the users' published posts with their associated topic:
$user->posts()->published()->with('topic')
Updates
Canvas follows Semantic Versioning and increments versions as MAJOR.MINOR.PATCH
numbers.
- Major versions will contain breaking changes, so follow the upgrade guide for a step-by-step breakdown
- Minor and patch versions should never contain breaking changes, so you can safely update the package by following the steps below:
You may update your Canvas installation using composer:
composer update
Run any new migrations using the canvas:migrate
Artisan command:
php artisan canvas:migrate
Re-publish the assets using the canvas:publish
Artisan command:
php artisan canvas:publish
To keep the assets up-to-date and avoid issues in future updates, you may add the canvas:publish
command to the post-update-cmd
scripts in your application's composer.json
file:
{ "scripts": { "post-update-cmd": [ "@php artisan canvas:publish --ansi" ] } }
Contributing
Thank you for considering contributing to Canvas! The contribution guide can be found here.
Testing
Run the tests with:
composer test
Troubleshooting
If you're running into problems, feel free to open a new issue or check the Discussions forum to see if anyone else has run into something similar.
License
Canvas is open-sourced software licensed under the MIT license.