laravel邮件发送
# 1文件上传
public function upload(Request $request){ if($request->isMethod('post')){ $file=$request->file('file');//获取上传文件 // 文件是否上传成功 if($file->isValid()){ // 获取文件相关信息 $originalName = $file->getClientOriginalName(); //文件原名 $ext = $file->getClientOriginalExtension(); //扩展名.jpg $realPath = $file->getRealPath(); //临时文件的绝对路径 $type = $file->getClientMimeType(); // image/jpeg $filename = date('Y-m-d') . '-' . uniqid() . '.' . $ext; //上传文件名 //这里的uploads是配置文件的名称 use Illuminate\Support\Facades\Storage;
$bool = Storage::disk('uploads')->put($filename, file_get_contents($realPath));
var_dump($bool);
} } return view('upload/show'); }
# 安装leravel
1. composer config -g repo.packagist composer https://packagist.phpcomposer.com #全局
2. composer create-project --prefer-dist laravel/laravel test 5.5.* #安装5.5
3. php artisan serve #启动
http://laravelacademy.org/resources-download #一键安装包
# 模板语法
compact('data',topics) #模板复值 {{$data}} #模板渲染 @if($el==true) @endif @foreach($data as $v) @endforeach
#模板定义
#layout/main.blade.php @yield('content') #定义不同部分
@include('layout.footer') #分开引入
#其他页面 @extends('layout.main') @section('content') <div class="col-sm-8 blog-main"> </div> @endsection
#数据迁移(migration )
php artisan make:migration create_posts_table public function up(){ Schema::create('posts', function (Blueprint $table) { $table->increments('id'); $table->string('title',100)->default(''); $table->text('content'); $table->integer('user_id')->default(0); $table->timestamps(); }); }
#数据填充
# bock\database\factories\UserFactory.php $factory->define(App\Entity\Posts::class, function (Faker $faker) { return [ 'title' => $faker->sentence(6), 'content' => $faker->paragraph(10), ]; }); php artisan tinker factory(App\Entity\Posts::class,20)->make(); #make 打印 create
# PUT提交表单
# 在form表单添加,修改为put提交
{{method_field("PUT")}} {{csrf_field()}} //token

浙公网安备 33010602011771号