LoginSignup
0
0

More than 1 year has passed since last update.

オリジナルアプリのデータベース登録で、createを使った。

Posted at

オリジナルアプリのデータベース登録で、悩みに悩み試しにcreateを使ってみることにしました。

モデルにfillable属性を追加

Playerdata.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Playerdata extends Model
{
    protected $table = 'playerdata';
    
    protected $fillable = ['playername', 'times_at_but', 'hit', 
        'hit_point', 'hit_adv', 'homeruns', 'steals', 'ining',
        'balls', 'hit_by_a_pitch', 'by_homeruns', 'wins', 
        'loses', 'saves', 'resp_points', 'lost_points', 'saved_adv'];
    
}

各コントローラーに処理を追加(追加部分)

ButterController.php
public function datainsert(){
        $dataname = new Dataname();
        
        $dataname->create([
            'playername' => '',
            'times_at_but' => '',
            'hit' => '',
            'hit_adv' => '',
            'homeruns' => '',
            'steals' => ''
        ]);
}
PitcherController.php
public function datainsert(){
        $dataname = new Dataname();
        
        $dataname->create([
            'playername' => '',
            'ining' => '',
            'balls' => 'testpassword',
            'hit_by_a_pitch' => '',
            'by_homeruns' => '',
            'wins' => '',
            'loses' => '',
            'saves' => '',
            'resp_points' => '',
            'lost_points' => '',
            'saved_adv' => ''
        ]);
    }

スクレイピングなので、値は空欄にしてあります。

結論

とりあえず、試しに書いてみただけなので、あっているかはわかりません。
データベース登録が無事にできればいいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0