Hi. I would like to add content management to my Spark app - authors can login and publish content through a backend with basic text editing and image upload (like any other blog/CMS). Is there any easy ways to get that functionality? I would love use Spark as my foundation, rather than using something like OctoberCMS..
I'd be interested to see where you take this. Me personally, I went with a markdown approach for "pages", with a custom controller. I enjoy the simplicity of creating MD files, dropping them into a folder, and done. Below is how I'm doing "pages".
I have a controller called MarkdownPageController, in it is the following:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Parsedown;
class MarkdownPageController extends Controller
{
/** @var This is the directory that stores the MD files */
private $markdown_dir;
/**
* Assign our variables
*/
public function __construct( Parsedown $parsedown )
{
$this->markdown_dir = base_path('content/');
$this->parsedown = $parsedown;
}
/**
* Attempts to parse a given file. If file does not exists the
* Laravel HTTP 404 error is generated.
*
* @uses abort() See more at: https://laravel.com/docs/5.2/errors#http-exceptions
* @param (string) $file_name The name of the markdown file
*/
public function getContent( $file_name )
{
$page_exists = @file_get_contents($this->markdown_dir.$file_name.'.md');
if ( $page_exists !== false ){
$content = $this->parsedown->text( $page_exists );
} else {
abort(404);
}
return $content;
}
/**
* Assigns a few variables, and passes it off to the view.
*/
public function show( $page )
{
return view('content', [
'slug' => strtolower( str_replace([' ','_'], '-', $page)),
'content' => $this->getContent( $page )
]);
}
}
Then later in my routes (its the last route), $router->get('/{page}', 'MarkdownPageController@show');