uri segment laravel not working for string









up vote
0
down vote

favorite












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=" route('barangs.edit',$barang->barang_kode) ">
<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?



answer :
add this code on my model



public $incrementing = false









share|improve this question



















  • 2




    Have you tried setting protected $incrementing = false on the model?
    – Travis Britz
    20 hours ago










  • it seems that I haven't used the code yet.
    – AdityaDS
    20 hours ago














up vote
0
down vote

favorite












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=" route('barangs.edit',$barang->barang_kode) ">
<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?



answer :
add this code on my model



public $incrementing = false









share|improve this question



















  • 2




    Have you tried setting protected $incrementing = false on the model?
    – Travis Britz
    20 hours ago










  • it seems that I haven't used the code yet.
    – AdityaDS
    20 hours ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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=" route('barangs.edit',$barang->barang_kode) ">
<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?



answer :
add this code on my model



public $incrementing = false









share|improve this question















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=" route('barangs.edit',$barang->barang_kode) ">
<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?



answer :
add this code on my model



public $incrementing = false






laravel laravel-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 19 hours ago

























asked 20 hours ago









AdityaDS

177113




177113







  • 2




    Have you tried setting protected $incrementing = false on the model?
    – Travis Britz
    20 hours ago










  • it seems that I haven't used the code yet.
    – AdityaDS
    20 hours ago












  • 2




    Have you tried setting protected $incrementing = false on the model?
    – Travis Britz
    20 hours ago










  • it seems that I haven't used the code yet.
    – AdityaDS
    20 hours ago







2




2




Have you tried setting protected $incrementing = false on the model?
– Travis Britz
20 hours ago




Have you tried setting protected $incrementing = false on the model?
– Travis Britz
20 hours ago












it seems that I haven't used the code yet.
– AdityaDS
20 hours ago




it seems that I haven't used the code yet.
– AdityaDS
20 hours ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













based on @Travis Britz comments
I get a solution that I have to add a some line at my model



protected $incrementing = false


on my case i need to change protected to public so the answer is



public $incrementing = false


and this working fine now






share|improve this answer




















  • My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
    – Travis Britz
    19 hours ago











  • no problem, at least you have helped me.
    – AdityaDS
    19 hours ago










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237334%2furi-segment-laravel-not-working-for-string%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













based on @Travis Britz comments
I get a solution that I have to add a some line at my model



protected $incrementing = false


on my case i need to change protected to public so the answer is



public $incrementing = false


and this working fine now






share|improve this answer




















  • My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
    – Travis Britz
    19 hours ago











  • no problem, at least you have helped me.
    – AdityaDS
    19 hours ago














up vote
0
down vote













based on @Travis Britz comments
I get a solution that I have to add a some line at my model



protected $incrementing = false


on my case i need to change protected to public so the answer is



public $incrementing = false


and this working fine now






share|improve this answer




















  • My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
    – Travis Britz
    19 hours ago











  • no problem, at least you have helped me.
    – AdityaDS
    19 hours ago












up vote
0
down vote










up vote
0
down vote









based on @Travis Britz comments
I get a solution that I have to add a some line at my model



protected $incrementing = false


on my case i need to change protected to public so the answer is



public $incrementing = false


and this working fine now






share|improve this answer












based on @Travis Britz comments
I get a solution that I have to add a some line at my model



protected $incrementing = false


on my case i need to change protected to public so the answer is



public $incrementing = false


and this working fine now







share|improve this answer












share|improve this answer



share|improve this answer










answered 20 hours ago









AdityaDS

177113




177113











  • My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
    – Travis Britz
    19 hours ago











  • no problem, at least you have helped me.
    – AdityaDS
    19 hours ago
















  • My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
    – Travis Britz
    19 hours ago











  • no problem, at least you have helped me.
    – AdityaDS
    19 hours ago















My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
– Travis Britz
19 hours ago





My mistake, you're right that the property is public. Without this, Laravel assumes that it's an incrementing integer, and casts your string to an int (probably 0). Related: stackoverflow.com/a/43691024/6038111
– Travis Britz
19 hours ago













no problem, at least you have helped me.
– AdityaDS
19 hours ago




no problem, at least you have helped me.
– AdityaDS
19 hours ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237334%2furi-segment-laravel-not-working-for-string%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線