samedi 10 novembre 2018

uri segment laravel not working for string

In my database, primary key has string and number likes ex : BRG2289182

My Controller

 public function edit(BarangModel $barang)
 {
     return view('fbarangs.edit',compact('barang'));
 }

My Model

class BarangModel extends Model
{
    protected $fillable = [
        'barang_kode',
        'barang_nama',
        'barang_jenis',
        'barang_hbeli',
        'barang_hjual',
        'barang_stok',
    ];

    protected $table = 'barangs';
    protected $primaryKey = 'barang_kode';
}

My routes

Route::resource('barangs','BarangController');

my link

<a class="btn btn-primary" 
  href="">
    <i class="fa fa-pencil"></i> 
</a>

I want to do routing for view, edit, delete. in my database, there is one primary key field that uses a mixture of letters and numbers. and the problem is when I use it for routing why can't it? but when I change the primary key data to a number, the result is successful. can anyone help me?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire