Laravel5.4简单笔记

laravel5的路由支持缓存。需要执行以下命令:

php artisan route:cache

清除应用程序缓存
php artisan cache:clear 

artisan命令清单
php artisan list

生成应用程序密钥
php artisan key:generate

生成配置缓存
php artisan config:cache

路由分组、中间件

Route::group(['middleware' => ['api.auth'],'namespace' => 'V1'], function () {
    Route::post('zone','ZoneController@create');
    Route::patch('zone/{zone_id}','ZoneController@edit');
    Route::delete('zone/{zone_id}','ZoneController@delete');
});    

注册短信服务提供者

namespace App\Providers;

use App\Sms\Sms;
use Illuminate\Support\ServiceProvider;

class SmsServiceProvider extends ServiceProvider
{
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(Sms::class, function() {
            return new Sms(config('sms'));
        });
    }
}

//修改 config/app.php 的providers下添加
App\Providers\SmsServiceProvider::class,

发送邮件

class Text extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(array $data)
    {
        //
        $this->data = $data ?? [];
        $this->data['content'] = (new Template($data))->get();
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.text')
            ->to($this->data['to'] ?? '422247668@qq.com')
            ->subject($this->data['subject'] ?? '')
            ->with('content', $this->data['content'] ?? '');
    }
}

//调用Mail发送
Mail::send(new Text([
    'to' => 'xxx@qq.com',
    'subject' => '邮件标题',
    'content' => '邮件内容'
]));