1. Go to this page and download the library: Download asuratu/boot-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asuratu / boot-laravel example snippets
// app/Providers/AppServiceProviders.php
namespace App\Providers;
use ZhuiTech\BootLaravel\Providers\LaravelProvider;
use ZhuiTech\BootLaravel\Providers\AbstractServiceProvider;
use ZhuiTech\BootLaravel\Providers\MicroServiceProvider;
// 基类ServiceProvider中提供了很多方便的注册机制,请查看源码了解
class AppServiceProvider extends AbstractServiceProvider
{
protected $providers = [
LaravelProvider::class,
];
}
// database/migrations/2018_04_04_122200_create_channels_table.php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateChannelsTable extends Migration
{
public function up()
{
Schema::create('channels', function (Blueprint $table) {
$table->increments('id');
// 添加需要的字段
$table->string('name')->comment('名称');
// ...
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('channels');
}
}
// app/Repositories/ChannelRepository.php
namespace App\Repositories;
use App\Models\Channel;
use ZhuiTech\BootLaravel\Repositories\BaseRepository;
// 基类BaseRepository提供了很多现成的方法,请查看源码了解
class ChannelRepository extends BaseRepository
{
function model()
{
return Channel::class;
}
}
// app/Http/Controllers/ChannelController.php
namespace App\Http\Controllers;
use App\Repositories\ChannelRepository;
use ZhuiTech\BootLaravel\Controllers\RestController;
// 基类ChannelController提供了很多现成的方法,请查看源码了解
class ChannelController extends RestController
{
public function __construct(ChannelRepository $repository)
{
parent::__construct($repository);
}
public function sample()
{
// 用以下方法会返回统一的数据格式
$this->success([]);
$this->fail('fail sample message');
}
}