bizprove / canvas
A Laravel publishing platform
This package's canonical repository appears to be gone and the package has been frozen as a result.
Fund package maintenance!
austintoddj
Requires
- php: >=7.1
- ext-json: *
- doctrine/dbal: ^2.6|^2.7|^2.8|^2.9|^2.10
- illuminate/support: ^5.6|^5.7|^5.8|^6.0
- spatie/laravel-blade-javascript: ^2.1|^2.2|^2.3|^2.4
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ^3.6|^3.7|^3.8|^4.0
- phpunit/phpunit: ^7.0|^8.0
- dev-master
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- 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.1.0-rc
- 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
This package is not auto-updated.
Last update: 2022-02-04 01:25:27 UTC
README
Table of Contents
Introduction
A Laravel publishing platform. Canvas is a fully open source package to extend your existing 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!
Installation
Note: Canvas requires you to have user authentication in place prior to installation. For Laravel 5.* based projects you may run the
make:auth
Artisan command to satisfy this requirement. For Laravel 6.* based projects please see the official guide to get started.
You may use composer to install Canvas into your Laravel project:
composer require cnvs/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
Usage
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 a simple UI at /canvas
by default. This can be changed by updating the path
option:
/* |-------------------------------------------------------------------------- | Base Route |-------------------------------------------------------------------------- | | This is the URI path where Canvas will be accessible from. You are free | to change this path to anything you like. Note that the URI will not | affect the paths of its internal API that aren't exposed to users. | */ 'path' => env('CANVAS_PATH_NAME', 'canvas'),
If you'd like to restrict access to Canvas in a production environment, add any custom middleware to the following array:
/* |-------------------------------------------------------------------------- | 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', 'auth', ],
Publishing
Canvas takes care of the backend while giving you the freedom to display the final content however you choose. A very simple setup would include a controller, some views, and a few routes. Take a look at the following example:
Define a few routes inside of routes/web.php
:
// Get all published posts Route::get('blog', 'BlogController@getPosts'); // Get posts for a given tag Route::get('tag/{slug}', 'BlogController@getPostsByTag'); // Get posts for a given topic Route::get('topic/{slug}', 'BlogController@getPostsByTopic'); // Find a single post Route::middleware('Canvas\Http\Middleware\ViewThrottle')->get('{slug}', 'BlogController@findPostBySlug');
Add the corresponding methods inside of a new BlogController
:
public function getPosts() { $data = [ 'posts' => \Canvas\Post::published()->orderByDesc('published_at')->simplePaginate(10), ]; return view('blog.index', compact('data')); }
public function getPostsByTag(string $slug) { if (\Canvas\Tag::where('slug', $slug)->first()) { $data = [ 'posts' => \Canvas\Post::whereHas('tags', function ($query) use ($slug) { $query->where('slug', $slug); })->published()->orderByDesc('published_at')->simplePaginate(10), ]; return view('blog.index', compact('data')); } else { abort(404); } }
public function getPostsByTopic(string $slug) { if (\Canvas\Topic::where('slug', $slug)->first()) { $data = [ 'posts' => \Canvas\Post::whereHas('topic', function ($query) use ($slug) { $query->where('slug', $slug); })->published()->orderByDesc('published_at')->simplePaginate(10), ]; return view('blog.index', compact('data')); } else { abort(404); } }
public function findPostBySlug(string $slug) { $posts = \Canvas\Post::with('tags', 'topic')->published()->get(); $post = $posts->firstWhere('slug', $slug); if (optional($post)->published) { $data = [ 'author' => $post->author, 'post' => $post, 'meta' => $post->meta, ]; // IMPORTANT: You must include this event for Canvas to store view data event(new \Canvas\Events\PostViewed($post)); return view('blog.show', compact('data')); } else { abort(404); } }
Finally, just create index.blade.php
and show.blade.php
inside a /views/blog
directory.
If you'd rather have all of this run automatically with no extra work from you, just follow through the optional guide below to build a Medium-inspired frontend. Aside from general post listings, you'll get localized content, reading suggestions and more!
Options
Note: The following components are optional features, you are not required to use them.
Want to get started fast? Just run php artisan canvas:setup
after installing Canvas. A --data
option may also be included in the command to generate demo data. Then, navigate your browser to http://your-app.test/blog
or any other URL that is assigned to your application. This command scaffolds a default frontend for your entire blog!
If you want to include Unsplash images in your post content, 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'), ],
Want a weekly summary? Canvas provides support for a weekly e-mail that gives you quick stats of the content you've authored, delivered straight to your inbox. Once your application is configured for sending mail, update config/canvas.php
:
/* |-------------------------------------------------------------------------- | Weekly Digest |-------------------------------------------------------------------------- | | This option enables Canvas to send e-mail notifications via the default | mail driver on a weekly basis. All users that have published content | will receive a total view count summary of the last seven days. | */ 'digest' => [ 'enabled' => env('CANVAS_DIGEST_ENABLED', false), ],
Since the weekly digest 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
Prefer working at night? Simply un-comment the Canvas::night()
method in the CanvasServiceProvider
to switch off the lights.
Updates
You may update your Canvas installation using composer:
composer update
Run any new migrations using the migrate
Artisan command:
php artisan migrate
Re-publish the assets using the canvas:publish
Artisan command:
php artisan canvas:publish
Testing
Run the tests with:
composer test
License
Canvas is open-sourced software licensed under the MIT license.
Credits
- The team that continues to support and develop this project
- Logo design and branding by Katerina Limpitsouni
- Thanks to Mohamed Said and his open source project Wink
- Anyone who has contributed a patch or made a helpful suggestion