`
810364804
  • 浏览: 784633 次
文章分类
社区版块
存档分类
最新评论

Laravel 一步步写Laravel CMS(二)——后台文章发布

 
阅读更多
Laravel Administrator在后台集成了很多的功能,于是我们不需要那么多配置,接下来让我们做一个如下所示的,文章发布:

转载保留:(转载自Phodal's BlogPhodal's CSDN)

创建一个Migrations

运行下面的代码

php artisan migrate:make create_posts_table

修改这个数据表


<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration {

	public function up()
	{
		Schema::create('posts',function(Blueprint $table)
		{
			$table->increments('id');
			$table->string('author')->default('admin');
			$table->longtext('post_content');
			$table->text('post_title');
			$table->timestamps();	

		});
	}

	public function down()
	{
		Schema::drop('posts');
	}

}

我们设置得简单一点,content和title,放article可能会比content好一点,


创建Posts Class

在modals新建一个Posts.php
<?php

class Posts extends Eloquent {
	public static $rules=array
	(
		'post_title'=>'required',
		'post_content'=>'required',
	);

}

这里设置标题和内容是必须的,不过作者有时候也是必须的,视个人而定的,我还是比较喜欢简单有效的这种方法 。

创建posts.php

在app/config/administrator新建一个Posts.php

<?php

return array(

	'title' => '文章',
	'single' => '内容',
	'model' => 'Posts',
	'form_width' => 960,

	'columns' => array(
		'author' => array(
			'title' => '作者',
			'select' => "author",
		),
		'post_title'=>array(
			'title'=>'标题',
			'select'=>'post_title',
		),
		'post_content'=>array(
			'title'=>'内容',
			'select'=>'post_content',
			'limit' => 30, 
		),
		'updated_at'=>array(
			'title'=>'发布日期',
			'select'=>'updated_at',
			'sort_field'=>'updated_at',
		),
	),


	'filters' => array(
		'author' => array(
			'title'=>'作者',
		),
		'post_title'=>array(
			'title'=>'标题',
			'type'=>'text',
		),
		'post_content'=>array(
			'title'=>'内容',
			'type'=>'text',
		),
		'updated_at'=>array(
			'title'=>'时间',
			'type'=>'date',
		),

	),

	'edit_fields' => array(
		'post_title'=> array(
			'title'=>'标题',
			'type'=>'text',
		),
		'post_content'=>array(
			'title'=>'内容',
			'type'=>'wysiwyg',
		),
	),

);

'title' => '文章',
'single' => '内容',
'model' => 'Posts',
'form_width' => 960,
前三个就不用多说了,form_wdith批的是编辑时候的宽度,这里设置的是960,暂时用这个值。
columns 用于展示,也就是刚看到的图片的左侧区

filters 用于右侧的筛选,也相当于搜索


Laravel Administrator type

Administrator类型有以下这些
这个可以参考官网提供的帮助,我们主要用到的是其中的WYSIWYG
这里用的editor是ckeditor
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics