質問編集履歴
2
StoreBlog.phpの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -494,6 +494,118 @@
|
|
494
494
|
|
495
495
|
|
496
496
|
|
497
|
+
app/Http/Requests/StoreBlog.php
|
498
|
+
|
499
|
+
```
|
500
|
+
|
501
|
+
<?php
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
namespace App\Http\Requests;
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
use Illuminate\Foundation\Http\FormRequest;
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
class StoreBlog extends FormRequest
|
514
|
+
|
515
|
+
{
|
516
|
+
|
517
|
+
/**
|
518
|
+
|
519
|
+
* Determine if the user is authorized to make this request.
|
520
|
+
|
521
|
+
*
|
522
|
+
|
523
|
+
* @return bool
|
524
|
+
|
525
|
+
*/
|
526
|
+
|
527
|
+
public function authorize()
|
528
|
+
|
529
|
+
{
|
530
|
+
|
531
|
+
return true;
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
/**
|
538
|
+
|
539
|
+
* Get the validation rules that apply to the request.
|
540
|
+
|
541
|
+
*
|
542
|
+
|
543
|
+
* @return array
|
544
|
+
|
545
|
+
*/
|
546
|
+
|
547
|
+
public function rules()
|
548
|
+
|
549
|
+
{
|
550
|
+
|
551
|
+
return [
|
552
|
+
|
553
|
+
'title' => 'required|string|max:50',
|
554
|
+
|
555
|
+
// 'target_site' => 'required',
|
556
|
+
|
557
|
+
'content' => 'required|string|max:500',
|
558
|
+
|
559
|
+
'tags' => 'json|regex:/^(?!.*\s).+$/u|regex:/^(?!.*/).*$/u',
|
560
|
+
|
561
|
+
];
|
562
|
+
|
563
|
+
}
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
public function attributes()
|
568
|
+
|
569
|
+
{
|
570
|
+
|
571
|
+
return [
|
572
|
+
|
573
|
+
'title' => 'タイトル',
|
574
|
+
|
575
|
+
// 'target_site' => '鍛えた部位',
|
576
|
+
|
577
|
+
'content' => '本文',
|
578
|
+
|
579
|
+
'tags' => 'タグ',
|
580
|
+
|
581
|
+
];
|
582
|
+
|
583
|
+
}
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
public function passedValidation()
|
588
|
+
|
589
|
+
{
|
590
|
+
|
591
|
+
$this->tags = collect(json_decode($this->tags))
|
592
|
+
|
593
|
+
->slice(0, 5)
|
594
|
+
|
595
|
+
->map(function ($requestTag) {
|
596
|
+
|
597
|
+
return $requestTag->text;
|
598
|
+
|
599
|
+
});
|
600
|
+
|
601
|
+
}
|
602
|
+
|
603
|
+
}
|
604
|
+
|
605
|
+
```
|
606
|
+
|
607
|
+
|
608
|
+
|
497
609
|
### 試したこと
|
498
610
|
|
499
611
|
|
1
補足の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -505,3 +505,11 @@
|
|
505
505
|
|
506
506
|
|
507
507
|
### 補足情報(FW/ツールのバージョンなど)
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
php 7.4.14
|
512
|
+
|
513
|
+
Laravel Framework 8.28.1
|
514
|
+
|
515
|
+
vue 2.6.11
|