coopers98/genericcrud

一个通用的CRUD控制器特性和相应的视图

安装: 504

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 1

公开问题: 0

语言:HTML

5.6 2018-06-05 12:48 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:23:04 UTC


README

GenericCRUD

一个Laravel通用CRUD控制器特性和相应的视图,以轻量级的方式在Laravel中搭建数据库表。

这个包是从最初为Kohana编写的纯GenericUpdate包演变而来的,现在最终用于Laravel。因此,虽然可能有许多更好的完成任务的方法,但这个包已经存在了一段时间。

安装

composer require coopers98/genericcrud

服务提供者

在你的应用配置中,将GenericCRUD添加到提供者数组中。

'providers' => [
    coopers98\GenericCRUD\GenericCRUDServiceProvider::class,
    ];

使用

请注意,这个包目前并不是一个真正的即插即用包。你可能需要稍微深入研究源代码来理解它是如何工作的。别担心,它非常直观,应该不难理解。

这是一个特性,所以你应该将它用于希望拥有通用CRUD功能的控制器上。

在你的routes.php文件中添加资源

Route::resource( 'post', 'PostController' );

创建你的控制器并使用该特性


use coopers98\GenericCRUD\GenericCRUD;

class PostController extends Controller {
	use GenericCRUD;

	public function __construct() {
		parent::__construct();

        	//
        	//  The name of the database table
        	//
		$this->table_name   = 'posts';

		//
		//  Name of the resource link from your routes file
		//
		$this->resourceLink = 'post';

		//
		//  Optional overrides/settings
		//
		//  Ignored columns will not be shown in the views
	    	//  $this->ignored_columns = [ 'created_at', 'updated_at', 'deleted_at' ];
	    	//
	    	//  Readonly columns will not be allowed to be edited (such as id fields, set by default )
	    	//  $this->readonly_columns = [ 'id' ];
	    	//
        
		//  Override the master template
		//  $this->masterTemplate = 'some_layout';
        	//
		
        	//  You can override any of the blade views to customize the display of the dataset
        	//  $this->showView 		= 'post.show';
	    	//  $this->indexView 		= 'post.index';
		//  $this->confirmDeleteView 	= 'post.confirm_delete';
		//  $this->editView 		= 'post.edit';
		//  $this->createView 		= 'post.create';

        	//
        	//  Call the populate columns function to load column data
        	//
		$this->populateColumns();
	}

}

完成这些操作后,默认情况下,你将拥有基本的CRUD功能

索引 显示 创建 存储 编辑 更新 删除

此外,你可以覆盖资源动作以收集更多数据、提供更多数据或以其他方式更改功能。

每个动作还会调用授权检查。

	public function authorizeDelete() {
		//  Override this function and redirect or otherwise to prevent the action from completing
		//  The return value is not checked, so you should just return a redirect response here
	}

此包还包括一个通用的表格导出器,它使用League/CSV包将给定的索引视图导出为csv文件。

许可证

GenericCRUD是开源软件,许可协议为MIT许可证