Route::middleware(['auth:sanctum', 'verified'])->any('/edit_eshop/{eshop}', function () {
return view('edit_eshop');
})->name('eshop.edit');
my controller:
public function edit_eshop(Eshop $eshop,Request $request){
if ($request->method() == 'POST'){
$eshop->title = $request->get('title');
$eshop->link = $request->get('link');
$eshop->telephone = $request->get('telephone');
$eshop->email = $request->get('email');
$eshop->payathome = $request->get('payathome');
$eshop->paywithcard = $request->get('paywithcard');
$eshop->tags = $request->get('tags');
if($eshop->save()){
echo "Το eshop δημιουργ?θηκε επιτυχ??.";
return redirect('/eshops');
};
};
return view('edit_eshop', ['eshop' => $eshop]);
}
<form action="" method="POST">
@csrf
<input type="text" name="title" placeholder="Ονομασ?α eshop" class="form-control" value={{ $eshop->title }}>
<input type="text" name="link" placeholder="Ηλεκτρονικ? διε?θυνση eshop" class="form-control" value={{ $eshop->link }}>
...
</form>
...
It suggests me :
$eshop is undefined
Make the variable optional in the blade template. Replace {{ $eshop }}
with {{ $eshop ?? '' }}
I 've already tried this , but keep getting empty fields in the form.
question from:
https://stackoverflow.com/questions/65713757/laravel8-errorexception-undefined-variable-eshop-view-opt-lampp-htdocs-all 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…