I want database column value within Form.
I search and try many way but there is no way to get database column value in Form.
e.g I want to get value of User(table) id
$user->id but no way to get the value.
how about this?
$form->model()->colum_name;
$form->model()->colum_name;
I already tried but no vlaue can retrieve.
I do a little research and found.
Form is not same as Grid and before return the Form there is no value from database is retrieve.
class UserController extends Controller
{
public function edit($id)
{
....
$content->body($this->form($id)->edit($id));
....
}
public function form($id = null)
{
// Get database value here
if ($id) {
$user = User::find($id);
}
.....
}
}
@z-song this returns null for me
@simonpeters
you need to pass (id) like this.
$this->form($request->id);
@z-song i have a same proplem with @zinmyotun-gic
my code:
protected function form()
{
return Admin::form(Stock::class, function (Form $form) {
$form->model()->id;
}
}
and this return null
pls help me
I tried to access the model value, but it is only accessing the model, not the real object. So, I made it as follows:
$id = request()->route()->parameter('<route_param_name>');var_dump(request()->route()->parameters());model = $form->model()->find($id);So, the final code of mine was:
if ($form->isEditing())
{
$id = request()->route()->parameter('config');
$model = $form->model()->find($id);
}
overwirte the following code:
public function edit($id, Content $content)
{
return $content
->title($this->title())
->description($this->description['edit'] ?? trans('admin.edit'))
->body($this->form($id)->edit($id));
}
I tried to access the model value, but it is only accessing the model, not the real object. So, I made it as follows:
- Get the ID of model from the route as follows:
$id = request()->route()->parameter('<route_param_name>');
Here, "route_param_name" is the binding key, which can be found by just dumpingvar_dump(request()->route()->parameters());
@lambae96 in your case it will be 'stock'- Get the object by ID:
model = $form->model()->find($id);So, the final code of mine was:
if ($form->isEditing()) { $id = request()->route()->parameter('config'); $model = $form->model()->find($id); }
thanks a lot dude, works for me
Most helpful comment
I tried to access the model value, but it is only accessing the model, not the real object. So, I made it as follows:
$id = request()->route()->parameter('<route_param_name>');Here, "route_param_name" is the binding key, which can be found by just dumping
var_dump(request()->route()->parameters());@lambae96 in your case it will be 'stock'
model = $form->model()->find($id);So, the final code of mine was:
if ($form->isEditing()) { $id = request()->route()->parameter('config'); $model = $form->model()->find($id); }