Latest

Monday, July 10, 2017

explode the retrieved values from db and display it in list view in laravel

Asked by: nishanthi


Controllercode:

    public function testjoin()
    {
        $test=supportedversionsModel::join('MainHaghway', 'MainHaghway.buildid', '=','HaghwaySupports.build_id')
        ->select('MainHaghway.versions','HaghwaySupports.supportedversions','MainHaghway.timestamputc','MainHaghway.updatedescription','MainHaghway.checkcount','MainHaghway.statuscode')->get();
        return view('haghwayUpdate',compact('test'));

    }
}

Here I have joined two tables which has one to many relationship.And returning the results to the view.

View code:

      <table class="table" id="table">

        <thead>
          <tr class="header">
              <th valign="middle" width="3%">Versions</th>
              <th valign="middle" width="2%">Supportedversions</th>
              <th valign="middle" width="7%">Release Date</th>
              <th valign="middle" width="3%">Type</th>
              <th valign="middle" width="7%">Description</th>
              <th valign="middle" width="3%">Actions</th>
              <th valign="middle" width="3%">Downloader</th>
              <th valign="middle" width="3%">Beta code</th>

            </tr>
            </thead>
            <tbody>
             @foreach($test as $user)
             <tr>
            <td>{{$user->versions}}</td>
            <td>{{$user->supportedversions}}</td>
          <td>{{$user->timestamputc}}</td>
          <td><a href="">Groups</a></td>
          <td>{{$user->updatedescription}}</td>
          <td>{{$user->statuscode}}</td>
          <td>{{$user->checkcount}}</td>
         **<td>{{"<li>" . str_replace ("," , "</li><li>" , $user->supportedversions) . "</li>"}}</td>**
          <td></td>


            </tr>
          @endforeach

            </tbody>

                </table>

This is my view code. Here I am just displaying the retrieved values in table.The attached image file is the table view that displays the db values. But here in the second column holds the imploded values,there I need to explode the values and display it in list view.


Answers

Answered by: Bilal Ahmed at 2017-07-11 11:59AM



you need to decode html entities. For example <p>some text </p> if you see this and you want to convert into paragraph then used this

<?php echo htmlspecialchars_decode(stripslashes($your_variable)); ?>

for more details please read manual



Answered by: JYoThI at 2017-07-11 12:04PM



1st : you missed Ul or OL tag that's why it's not listing

Note : li tag should be enclosed by ul tag ol tag

2nd : use strip_tags() function strips a string from HTML, XML, and PHP tags.

3rd: use {!! .. !!}

 <td>{!! "<ul><li>" . str_replace ("," , "</li><li>" , strip_tags($user->supportedversions)) . "</li> </ul>" !!}</td>


Answered by: Zaheer Attar at 2017-07-11 12:26PM Accepted



I can understand what you need to do.

As per Laravel Documentation about slot i.e. {{ }}. Anything written inside {{ }} except variables are considered as string (Its echo in Laravel).

So as per your requirement, you should use {!! !!}, which more advance and it'll allow you to use HTML Elements as string. You'll find more detailed info in this answer.




Source

No comments:

Post a Comment

Adbox