小编Ede*_*dio的帖子

如何将上传的图像保存到laravel中的存储?

我正在使用图像干预将图像保存到存储文件夹.我有下面的代码,它似乎只是保存带有空白图像的文件名.我想我需要一种方法将文件内容写入文件夹但是却在为片段而苦苦挣扎.

if ($request->hasFile('photo')) {
            $image      = $request->file('photo');
            $fileName   = time() . '.' . $image->getClientOriginalExtension();

            $img = Image::make($image->getRealPath());
            $img->resize(120, 120, function ($constraint) {
                $constraint->aspectRatio();                 
            });

            //dd();
            Storage::disk('local')->put('images/1/smalls'.'/'.$fileName, $img, 'public');
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5

6
推荐指数
1
解决办法
3万
查看次数

使用 NgModel 绑定到 Angular Material 的单选组输入

我有一个无线电组,我想从我的组件代码中设置它的值。但是我似乎无法使用 [(ngModel)] 设置初始值。我没有收到任何错误或任何内容来说明为什么它没有显示选中的单选按钮。

<div class="form-group">
  <mat-radio-group  [(ngModel)]="selectedStatus" formControlName="completed">
    <mat-radio-button  [value]="1">Call Complete</mat-radio-button>
    <mat-radio-button [value]="2">Call Incomplete</mat-radio-button>
  </mat-radio-group>
</div>
Run Code Online (Sandbox Code Playgroud)

组件代码片段:

selectedStatus: Array<string>;



private initForm() {
    this.eventEditForm = new FormGroup({          
      'completed': new FormControl()
      });          
      this.selectedStatus = this.data[0].completed;
    }
Run Code Online (Sandbox Code Playgroud)

this.data[0].completed 从数据服务返回 1 或 2。

angular-material angular

6
推荐指数
1
解决办法
3万
查看次数

Laravel迁移错误

我似乎无法弄清楚为什么我在此迁移文件上收到此错误?

错误

[37; 41m [Symfony \ Component \ Debug \ Exception \ FatalThrowableError]?[39; 49m?[37; 41m在null上调用成员函数nullable()?[39; 49m

文件上的日期是在Customer表中创建外部ID之后的日期。这是laravel 5.3。如何解决此错误?

public function up()
{
    Schema::create('invoices', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();           
        $table->integer('customer_id')->unsigned();
        $table->timestamps('date_from')->nullable();
        $table->timestamps('date_to')->nullable();
        $table->date('invoice_date')->nullable();
        $table->date('due_at')->nullable();     
        $table->integer('total_charge')->nullable();
        $table->integer('rate')->nullable();
        $table->integer('total_hours')->nullable();
        $table->string('status')->nullable();
        $table->string('description', 255)->nullable();
        $table->string('notes', 255)->nullable();
        $table->string('invoice_ref')->nullable();  

        $table->foreign('customer_id')
              ->references('id')->on('customers')
              ->onDelete('cascade');                      
    });
}
Run Code Online (Sandbox Code Playgroud)

laravel-5.3

5
推荐指数
1
解决办法
2751
查看次数

在 Nestjs 中使用类验证器验证嵌套对象

我在验证嵌套对象时遇到困难。使用类验证器运行nestJs。顶级字段(名字、姓氏等)验证正常。Profile 对象在顶层验证正常,即如果我作为数组提交,我会得到正确的错误,它应该是一个对象。

然而,Profile 的内容尚未得到验证。我已遵循文档上的建议,但也许我只是错过了一些东西。

有谁知道如何验证嵌套对象字段?

 export enum GenderType {
    Male,
    Female,
}

export class Profile {
    @IsEnum(GenderType) gender: string;
}

export class CreateClientDto {
    @Length(1) first_name: string;

    @Length(1) last_name: string;

    @IsEmail() email: string;

    @IsObject()
    @ValidateNested({each: true})
    @Type(() => Profile)
    profile: Profile; 
}
Run Code Online (Sandbox Code Playgroud)

当我发送此有效负载时,我预计它会失败,因为性别不在枚举或字符串中。但它并没有失败

{
   "first_name":"A",
   "last_name":"B",
   "profile":{
      "gender":1
   }
}
Run Code Online (Sandbox Code Playgroud)

class-validator nestjs

0
推荐指数
1
解决办法
9779
查看次数

如何使用 Nestjs 中注入服务的监听器监听事件?

我有一个监听事件的监听器,但我也希望该监听器调用其他服务来执行事件中的操作。即创建数据库通知,发送短信等。

当我创建一个构造函数来注入依赖的服务时,侦听器停止拾取事件,当我使用服务删除构造函数时,它会再次开始工作。

我需要如何构造这个监听器才能调用其他服务,例如下面示例中的NotificationsService?

客户端更新.listener.ts

    @Injectable()
    export class ClientUpdatedListener {

    constructor(
        @Inject(NotificationsService) private notificationService) {
    }

    private readonly logger = new Logger(ClientUpdatedListener.name);

    @OnEvent(eventType.CLIENT_UPDATED)
    handleClientUpdatedEvent(event: ClientUpdatedEvent) {
        this.logger.log('Processing event: ' + eventType.CLIENT_UPDATED );
        console.log(event);

       this.notificationService.emailClient(event.id);
    }
Run Code Online (Sandbox Code Playgroud)

通知服务。目前它是一个 shell,但我希望在其中执行逻辑并可能执行数据库调用。

@Injectable()
export class NotificationsService {

    constructor(
        @Inject(TENANT_CONNECTION) private tenantDb,
    ) {}
    
    emailClient(id: string) {
        console.log(id);
    } 
}
Run Code Online (Sandbox Code Playgroud)

调用服务代码

    const clientUpdatedEvent = new ClientUpdatedEvent();
    clientUpdatedEvent.id = id;
    this.eventEmitter.emit(eventType.CLIENT_UPDATED, clientUpdatedEvent);
Run Code Online (Sandbox Code Playgroud)

node.js nestjs

0
推荐指数
1
解决办法
4208
查看次数