Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tomopongrac's avatar

@jeetdholakia

Try this

public function viewmodal($societyid)
    {
        return "Works";
    } 

If that not working, maybe your route is not working

jeetdholakia's avatar

@tomo_pongrac I modified the code in controller to this:

$sd = DB::table('user')->where('societyid', '=', $societyid);
return view('admin.modalview', ['sd' => $sd]);  

If I use {{ $sd->societyname }} to output data in modalview I am getting error and if I am only using normal data such as HTML code then output is coming.

jeetdholakia's avatar

@tomo_pongrac Its coming when the modal is getting opened not by manually opening the link. Same thing is coming if i manually opening this link.

tomopongrac's avatar
Level 51

@jeetdholakia

Write this in controller

$sd = DB::table('user')->where('societyid', '=', $societyid);
return view('admin.modalview', ['sd' => $sd])->render();

You view must contain only html with data from variable...

for test you can write alert in javaScript

<script>
    $(document).ready(function(){
      $("#societydetails").on("show.bs.modal", function(e) {
        var id = $(e.relatedTarget).data('target-id');
        $.get('/admin/society/' + id, function( data ) {
        alert(data);
          $(".modal-body").html(data);
        });

      });
    });
  </script>
3 likes
jeetdholakia's avatar

@tomo_pongrac But in controller I am passing ['sd' => $sd] even if i change it to $sc in controller and everywhere getting the same error.

jeetdholakia's avatar

@tomo_pongrac I am doing that only but that undefined property error is coming. Code in modal body:

<table class="table table-striped">
  <tr>
    <td>Society ID</td>
    <td>{{ $sd->societyid }}</td>
  </tr>
  <tr>
    <td>Society Name</td>
    <td>{{ $sd->societyname }}</td>
  </tr>
</table>
tomopongrac's avatar

It looks like societyid dont exist in your database table

what hapens when you write

<table class="table table-striped">
  <tr>
    <td>Society Name</td>
    <td>{{ $sd->societyname }}</td>
  </tr>
</table>

or

<table class="table table-striped">
  <tr>
    <td>Society ID</td>
    <td>Some id</td>
  </tr>
  <tr>
    <td>Society Name</td>
    <td>Some name</td>
  </tr>
</table>
tomopongrac's avatar

@jeetdholakia

I didt see before but there is error in controller. You must add method first()

$sd = DB::table('user')->where('societyid', '=', $societyid)->first();
jeetdholakia's avatar

@tomo_pongrac FINALLY :) Yeah I tried it with get() method but not with first. Once again thank you so so much for helping me :)

kingpabel's avatar

You have to apply dynamic id like societydetails{{ $sd->id }} and use modal inside foreach using like that,may this technique will help you.

jeetdholakia's avatar

@kingpabel I have done that only, The thing I wanted is to get the data inside the modal according to ID.

Previous

Please or to participate in this conversation.