dimanche 2 juin 2019

laravel 5.8 get current model info from many to many relation

I have three table

  1. hotel

  2. hotel_feature

  3. hotel_feature_assing

hotel and hotel_feature have many to many relation

In hotel_feature_assing I will save id of hotel and id of the feature.

In edit section I have check box, I want to show check box checked if current hotel(editing one) have the feature. How can I check that the current hotel is already assigned to make checked my checkbox?

this is my Hotel Model:

  public function features()
    {
        return $this->belongsToMany(HotelFeature::class, 'hotel_feature_assigns');
    }

and in HotelFeature model:

  public function hotel()
   {
     return $this->belongsToMany(Hotel::class);
   }

this is my checkbox:

@foreach($hotelfeatures as $key => $hotelfeature)
                    <input type="checkbox" name="idhotelfeature[]" id="idhotelfeature" value=""
                        style="margin-right:5px" @if ($hotel->is_feature)
                    checked
                    @endif><span class="font-weight-normal"></span>
 @endforeach



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2QE5Fff
via IFTTT

Aucun commentaire:

Enregistrer un commentaire