1

I'm using laravel application and using modal form for edit.

When I use label as "title","des" and in modal "my-title" & "my-description" in two fields, it gets all the data but on the third field when I use any text such as "value" & "my-value" it doesn't get the data.

Also please help how to get data in dropdown menu. enter image description here

enter image description here

In this you can see data for phase total area and town is not getting in required fields.

Index.blade.php

                    @foreach($phases as $cat)
                        <tr>
                            <td>{{$cat->phase_name}}</td>
                            <td>{{$cat->phase_address}}</td>
                            <td>{{$cat->phase_totalarea}}</td>
                            <td>
                                {{ \Illuminate\Support\Facades\DB::table('towns')->where('id',$cat->town_id)->value('town_name')}}</td>
                            <td>
                                <button class="btn btn-info" 
                                data-mytitle="{{$cat->phase_name}}" 
                                data-mydescription="{{$cat->phase_address}}" 
                                data-myvalue="{{$cat->phase_totalarea}}" 
                                 data-mytown="{{$cat->town_id}}"
                                data-catid={{$cat->id}} data-toggle="modal" 
                                data-target="#edit">Edit</button>
                                /
                                <button class="btn btn-danger" data-catid={{$cat->id}} data-toggle="modal" data-target="#delete">Delete</button>
                            </td>
                        </tr>

                    @endforeach

Form.blade.php

    <label for="title">Phase Name</label>
    <input type="text" class="form-control" name="phase_name" id="title">
</div>

<div class="form-group">
    <label for="des">Phase Address</label>
    <textarea name="phase_address" id="des" cols="20" rows="5" class="form-control"></textarea>
</div>


<div class="form-group">
    <label for="value">Phase Total Area</label>
<input type="text" class="form-control " name="phase_totalarea" id="value"  >


</div>

@php
use Illuminate\Support\Facades\DB;
$twn=DB::table('towns')->get();
$counter=0;
@endphp

<div class="form-group row">

<label for="town" class="col-md-4 col-form-label">Select Town:</label>

<div class="col-md-4 col-form-label">
    <select name="town_id" class="form-control" style="width:360px" id="town" required autofocus>
        <option value="">--- Select Town ---</option>


        @foreach($twn as $town)
            @if($counter==-1)
                <option selected="selected" value="{{$town->id}}">{{$town->town_name}}</option>
                {{$counter++}}
            @else
                <option value="{{$town->id}}">{{$town->town_name}}</option>
            @endif
        @endforeach
    </select>
</div>
</div>
Abdul Rehman
  • 159
  • 1
  • 2
  • 18

1 Answers1

0

as you have not included the error i am guessing You need to involve jquery for that . make a function in datatable for on onclick like you did for the delete. and send data to function and then pass the data to modal via ID .that would be easy and professional way

   function openModalAndSendData(a){
     var title= $(a).attr('title');
     var desc = $(a).attr('desc ');
     var value= $(a).attr('value');

$('#Modal').modal('show');
        $('#title').val(title);
        $('#desc ').val(desc );
        $('#value').val(value);
    }

on modal get the data in input fields like

<label for="recipient-name" class="col-form-label"> title:</label>
<input type="text" class="form-control" id="title"  >

<label for="recipient-name" class="col-form-label"> desc :</label>
<input type="text" class="form-control" id="desc"  >

<label for="recipient-name" class="col-form-label"> value:</label>
<input type="text" class="form-control" id="value"  >
Hassan Tariq
  • 39
  • 1
  • 10
  • Can you tell how I can add the temporary expressions in controller and how will these modal will be called out from index page. As I add this I get "Can't use temporary expression in write context" – Abdul Rehman Mar 09 '21 at 09:56
  • on click you can change the value every time and this process start with controller . get list of data to view in datatable add button in datatable in every row and attr of onclick then in onclick function you will get the value from button attr and set the value in modal input by id and then open modal . on every click you pass new data and thats how you change data . no need to involve controller in it every time . how you inderstand – Hassan Tariq Mar 12 '21 at 10:34