laravel常用命令和操作

创建数据库:php artisan make:migration create_user_log_table --create=user_log
php artisan migrate
创建控制器:php artisan make:controller AdminController -r
创建model:php artisan make:model Models/Modelname
php artisan make:model Models/Modelname -m 会同时生成迁移文件

迁移数据库 php artisan

 使用redis
composer require predis/predis
 use Illuminate\Support\Facades\Redis;
 Redis::set('kw','afaf');
 echo Redis::get('kw');
 使用session

$request->session()->put('key', 'value1');
$value = $request->session()->get('key', 'default');
echo $value;
使用memcached

Cache::put('xiaohua','gasgasg',10);
Cache::put('aga','gasga555sg',10);
$flag = Cache::has('xiaohua');
$val = Cache::get(['xiaohua','aga']);
Cache::forget('xiaohua');
邮件发送

env配置
MAIL_DRIVER=smtp
MAIL_HOST=smtp.exmail.qq.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=SA41651616663^
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME=php君
 
控制器:
use Illuminate\Support\Facades\Mail;
 
$address = '[email protected]';
$this->address = $address;
 
//简单的邮件发送
$flag = Mail::send('test.index2',['name'=>'php君'],function($msg){
    $to = $this->address;
    $msg->to($to)->subject('邮件测试');
});
 
//纯文本的邮件发送
$flag = Mail::raw('杏子招客饮,十里稻花香',function($msg){
    $to = $this->address;
    $msg->to($to)->subject('测试邮件,谁?');
});
 
//带附件的邮件发送
Mail::send('emails.test',['name'=>$name,'imgPath'=>$imgPath],function($message){//带图片
//
//use Storage $image = Storage::get('images/test.jpg');获取本地视图
//
 $flag = Mail::send('test.index2',['name'=>'php君'],function($msg){
     $to = $this->address;
     $msg->to($to)->subject('邮件测试');
     $attachment = storage_path('download/员工列表模板.xlsx');
     $msg->attach($attachment,['as'=>'员工列表模板.xlsx']);
     //$msg->attach($attachment,['as'=>"=?UTF-8?B?".base64_encode('测试文档')."?=.doc"]);//解决乱码的问题
 });
 
if(count(Mail::failures())>0)
{
    pr('something went wrong..!!');
    return Response::json(array(
        'status'=>'error',
        'data'=>("something went wrong..!!")
    ), 200);
}else{
    pr('Your email has been sent successfully');
    return Response::json(array(
        'status'=>'success',
        'data'=>("Your email has been sent successfully")
    ), 200);
}
使用验证码

$ composer require mews/captcha
 
/config/app.php  配置
'providers' => [
    // ...
    Mews\Captcha\CaptchaServiceProvider::class,
]
'aliases' => [
    // ...
    'Captcha' => Mews\Captcha\Facades\Captcha::class,
]
 
$ php artisan vendor:publish 执行这个语句之后会出来几个选项
我们选择这条之前的序号回车 Provider: Mews\Captcha\CaptchaServiceProvider
运行之后,就可以在 config/captcha.php 中进行配置了。这里使用默认配置。

你可能感兴趣的:(laravel常用命令和操作)