Support the ongoing development of Laravel.io →
Database Blade Forms
Last updated 1 year ago.
0

Just add it when inserting into db?

email = $request->eMail . '@id.mail.com';

0
public function store_user(Request $req)
{
       mod_user::create($req->all());
       Session::flash('flash_message', 'User Data Saved');
	return redirect('adduser');
}
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class mod_user extends Model
{
	protected $table = 'tbl_user';
	protected $fillable = [
		'nama_user',
		'level_akses',
		'contact',
		'eMail',
		'password'
	];
	protected $guarded = ['status'];
}

how to do that? @Asser90

0

You can use mutators.

Accessors and mutators allow you to format Eloquent attributes when retrieving them from a model or setting their value. from laravel documentation.

If you want for some reason manipulate model attribute before saving to DB you can define a mutator method:

public function setEMailAttribute($value){
   $this->attributes['eMail'] = $value.'@id.mail.com';
}

Name of mutator method must be studly cased, and has word set before and word Attribute after it.

Last updated 7 years ago.
0

bikasoon said:

You can use mutators.

Accessors and mutators allow you to format Eloquent attributes when retrieving them from a model or setting their value. from laravel documentation.

If you want for some reason manipulate model attribute before saving to DB you can define a mutator method:

public function setEMailAttribute($value){
  $this->attributes['eMail'] = $value.'@id.mail.com';
}

Name of mutator method must be studly cased, and has word set before and word Attribute after it.

Thank you :D

0

Sign in to participate in this thread!

Eventy

Your banner here too?

DCHN04 dchn04 Joined 4 Oct 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.