With the rapid development of Internet technology, Web development has become the most popular technology at present. Many developers need to perform database operations in their daily work, and in most cases the operations involved are additions, deletions, modifications, and searches. So, how can these operations be completed quickly and efficiently?
For PHP developers, there is a very convenient way to automatically generate the addition, deletion, modification and query functions with one click, and that is to use the third-party class library "CRUDBooster".
CRUDBooster is an open source PHP class library that can quickly generate a management background interface. Developers only need to perform simple configuration to use it. Let’s learn how to use CRUDBooster!
Set permissions and auto-loading. Create a app
directory in the project root directory, then create a Http
directory under the app
directory, and create a Http
directory under it A Controllers
directory. Finally, create a file named CRUDController.php
in the Http
directory, and add the following code to the file:
<?php namespace App\Http\Controllers; use crocodicstudio\crudbooster\controllers\CBController; class CRUDController extends CBController { public function __construct() { $this->table = "table_name"; $this->primary_key = "id"; $this->title_field = "name"; } }
Among them, table_name
is the name of the table that needs to be operated, id
is the name of the primary key field in the table, name
is the name of the field that displays the name in the table.
Create a controller. Create a file named SampleController.php
in the app/Http/Controllers
directory, and add the following code to the file:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class SampleController extends Controller { public function index() { return view('sample.index'); } }
Create view files. Create a directory named sample
under the resources/views
directory, and create a file named index.blade.php
in that directory. Add the following code to the file:
@extends('crud::sample.layout') @section('content') <h1>Hello World</h1> @endsection
Add routes to the routes/web.php
file
Route::get('/', 'SampleController@index'); Route::get('admin/sample', 'Admin\CRUDController@index'); Route::get('admin/sample/add', 'Admin\CRUDController@add'); Route::post('admin/sample/add', 'Admin\CRUDController@addSave'); Route::get('admin/sample/detail/{id}', 'Admin\CRUDController@detail'); Route::get('admin/sample/edit/{id}', 'Admin\CRUDController@edit'); Route::post('admin/sample/edit/{id}', 'Admin\CRUDController@editSave'); Route::get('admin/sample/delete/{id}', 'Admin\CRUDController@delete');
At this point, the installation and settings of CRUDBooster have been completed. Next, we can start using it to automatically generate additions, deletions, modifications and queries with one click.
Since we have specified the table name, primary key field name and display name field name that need to be operated in the controller code, therefore , we only need to execute the following command to quickly generate the management background interface:
php artisan crudbooster:install
After running this command, CRUDBooster will automatically generate the add, delete, modify and check function, and will also generate the login page of the management background. We can pass Access the /admin path to enter the management background.
At this point, we can see the newly generated add, delete, modify and query pages under the /admin/sample
path. They are all based on Bootstrap style, and have implemented table search, Sorting, paging and other functions. In addition, CRUDBooster also generates functions such as data form validation and permission management for us.
There are many other powerful functions in CRUDBooster, such as file upload, email sending, data export, etc., which will not be described here.
Using CRUDBooster to automatically generate one-click addition, deletion, modification and query functions will undoubtedly make developers’ work more efficient and convenient. The advantage of CRUDBooster is not only that it is easy to use, rich in functions, and highly customizable, but also that it follows the best practices of the Laravel framework and can be easily integrated with Laravel projects.
I hope the above content can inspire and help everyone, thank you!
The above is the detailed content of Detailed explanation of the installation and settings of PHP CRUDBooster. For more information, please follow other related articles on the PHP Chinese website!