hello earth creatures ..
here I am trying to save form data using my mass assignment and primary key for costumes such as "cst-01, cst-02, ..., cst-N" can I save both of these together?
this my model
class pelanggan extends Model {
protected $table = 'tb_pelanggan';
protected $primaryKey = 'id';
public $incrementing = false;
protected $fillable = [
'id', // the id type string 255
'nama_pelanggan',
'no_tlpn_pelanggan',
'alamat_pelanggan',
'kategori_pelanggan',
'deskripsi_pelanggan'
];
}
this my controller, i make costum id here
public function storeCostumer(Request $req) {
$lastId = pelanggan::select('id')->where('id', 'like', 'cst-0%')->orderBy('id','desc')->first();
$lastId =(int)substr($lastId , -3)+1;
$newID = "cst-0".$lastId; //costume ID
pelanggan::create($req->all());// all() only save data form. how i can save the id?
return redirect('newCostumer');
}
sorry for my bad english and thanks for your times
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NlnrUH
via IFTTT
Aucun commentaire:
Enregistrer un commentaire