z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.12k stars 2.81k forks source link

how to fetch the id in grid to form controller? #5806

Closed jesnagifto closed 11 months ago

jesnagifto commented 1 year ago

Description:

can not saving the form field

protected function form()

{

    $request = Request::all();  

  $user_id =intval($request['user_id']);

    // $id = $form->model()->id;
        $custregisterId = Custregister::where('id', $user_id)->first();

    $form = new Form(new Business()); // Use the Bussiness model

     $form->radioCard('custmer', __('custmer'))->options(['1'=> 'Customer Details'])
    ->when(1, function (Form $form) use($custregisterId) {

    $form->text('candidate_name', __('Candidate Name'))->value($custregisterId->candidate_name);
    $form->text("fathers_name", __("Father's Name"))->value($custregisterId->fathers_name);
    $form->text("mothers_name", __("Mother's Name"))->value($custregisterId->mothers_name);
    $form->textarea('house_name', __('Address '))->rows(5)->style('width', '300px; height: 150px;')->value($custregisterId->house_name);
    $form->mobile('mob_1', __('First Mobile Number'))->options(['mask' => '999 999 9999'])->setWidth(4, 2)->value($custregisterId->mob_1);
    $form->mobile('mob_2', __('Second Mobile Number'))->options(['mask' => '999 999 9999'])->setWidth(4, 2)->value($custregisterId->mob_2);
    $form->date('date_of_birth', __('Date of Birth'))->default(date('Y-m-d'))->setWidth(4, 2)->value($custregisterId->date_of_birth);
   // $form->number('age', __('Age'))->value($custregisterId->age);
    //$form->text('religion', __('Religion'))->setWidth(4, 2)->value($custregisterId->religion);
   // $form->text('cast', __('Cast'))->value($custregisterId->cast);
    });

    $form->date('date', __('Date'))->default(date('Y-m-d'));
    $form->time('in_time', __('In Time'))->default(date('H:m'));
    $form->textarea('expectations', __('Expectations'))->rows(5)->style('width', '650px; height: 300px;');
    $form->text('family_status', __('Family Status'));
    $form->textarea('house_details', __('House Details'))->rows(5)->style('width', '300px; height: 150px;');
    $form->textarea('service_charge_details', __('Service Charge Details'))->rows(5)->style('width', '300px; height: 150px;');
    $form->textarea('matching_profile_details', __('Matching Profile Details'))->rows(5)->style('width', '300px; height: 150px;');
    $form->text('payment_chance', __('Payment Chance'));
    $form->textarea('payment_details', __('Payment Details'))->rows(5)->style('width', '300px; height: 150px;');
    $form->text('offer', __('Offer'));
    $form->text('location', __('Location'));
    $form->text('landmark', __('Landmark'));
    $form->text('latitude', __('latitude'));
    $form->text('longitude', __('longitude'));
    $form->map('latitude' , 'longitude', 'Map')->useGoogleMap();
    // $form->map('latitude', 'longitude')->useGoogleMap();
    $form->time('out_time', __('Out Time'))->default(date('H:m'));
    $form->textarea('remark', __('Remark'))->rows(5)->style('width', '300px; height: 150px;');

   // $form->saving(function (Form $form) use ($custregister) {

           // $custregisterId = $form->input('id');

// // Set the vca_id field with the corresponding id from the latest Custregister record // $form->model()->fathers_name = $custregister->fathers_name; // $form->model()->candidate_name = $custregister->candidate_name; // $form->model()->mothers_name = $custregister->mothers_name; // $form->model()->house_name = $custregister->house_name; // $form->model()->mob_1=$custregister->mob_1; // $form->model()->mob_2 = $custregister->mob_2; // $form->model()->date_of_birth = $custregister->date_of_birth;

  //  });

    return $form;

error detecting the 129 th line... please solve this.

Steps To Reproduce:

Screenshot 2023-08-08 101539 this picture id is fetch the details in table, but can not save the form Screenshot 2023-08-08 101707

alexoleynik0 commented 11 months ago

Have you tried to add hidden field with "user_id" as name and then removing it from form's data in a callback?

$user_id = intval($request['user_id']);
// ...
$form->hidden('user_id', $user_id);
// ... 
$form->ignore(['user_id']);

This way user_id should appear in the Form submission request values (eg request('user_id')) but won't trigger DB saving error, because it will not be added to Business's model data.