0

I have the system where I can manually change the database and the bike id will link to the favourite id and will show on the favourite page.

What I need now is to allow the user to click a favourite button on the bike img and it will save the bike for them to view on their favourites page

I have tried a few different options but can not get anything to work as yet, apart from manually changing the database to show information

this is the favourites page code:

@foreach($bike->favourites as $favourite)
        <div class="grid">
          <img src="{{ $bike->bike_img }}">
          <div class="item {{ $bike->bike_category }} {{ $bike->bike_category2 }}">
          <h2>{{ $bike->bike_name }}</h2>
          <a href="{{ $bike->bike_url }}" target="_blank">Buy this bike</a>
    </div></div>
@endforeach

this is where the bikes show:

@foreach($bikes as $bike)
  <div class="item {{ $bike->bike_category }} {{ $bike->bike_category2 }}">
    <h2>{{ $bike->bike_name }}</h2>
    <img src="{{ $bike->bike_img }}"><br><br>
    <a href="{{ $bike->bike_url }}" target="_blank">Buy this bike</a>
    <a href="" class="favebutton"><i class="far fa-heart"></i></a>
  </div>        
@endforeach

I think I need the favebutton to be a form that will submit and take the user id, attach it to the favourite database which will then show on the favourites page. This would be the ideal outcome.

When the user clicks the fave button it will then bring it into the favourite database and show on the favourite page

party-ring
  • 1,761
  • 1
  • 16
  • 38
  • you need to read on https://laravel.com/docs/5.8/eloquent-relationships#many-to-many and post form routes – Ahmed Aboud May 03 '19 at 13:30
  • I have all my relationships working ok. I can manually give the bike and favourite databases ID's and it will show the bike in the users favourite page. The only thing I need now is to know how to get the user to click a button and send that information to the database. – Joshua Rolloos May 03 '19 at 14:01
  • and in routes/web.php you make a post route check https://www.5balloons.info/example-form-submission-validation-laravel/ – Ahmed Aboud May 03 '19 at 20:39

0 Answers0