use Illuminate\Database\Eloquent\Model;
class Posting extends Model
protected $table = 'posting';
* createメソッド実行時に、入力を禁止するカラムの指定
protected $guarded = array('id');
static function addPost($request,$target_id = 0)
$post = Posting::create([
'target_id' => $target_id,
'name' => $request['name'],
'comment' => $request['comment'],
'mail_address' => $request['mail_address'],
'password' => $request['password'],
if(isset($request['files']))
foreach($request['files'] as $value)
$file = file_get_contents($value);
$mime = $value->getMimeType();
'target_id' => $post->id,
static function editPost($id,$request)
Posting::query()->where('id',$id)->update([
'name' => $request['name'],
'comment' => $request['comment'],
'mail_address' => $request['mail_address'],
if(isset($request['files']))
UploadFile::query()->where('target_id',$id)->delete();
foreach($request['files'] as $value)
$file = file_get_contents($value);
$mime = $value->getMimeType();
static function deletePost($id,$request)
Posting::query()->where('id',$id)->delete();
UploadFile::query()->where('target_id',$id)->delete();