wuschelino22
4 months ago
137
28
Laravel

Edit Blade View

Posted 4 months ago by wuschelino22

Hello, i want to build a edit view that only shows the data for the one i want to edit in my edit.blade.php I use the follow foreach at the moment on my blade. But it only shows me every thing.

@foreach($shares as $share)


<div class="panel panel-default">
      <div class="panel-heading">
      
      </div>
      <div class="panel-body">
        <form class="form-horizontal" action="{{ route('shares.edit',$share->id) }}" method="POST">
          {{ csrf_field() }}
        <fieldset>

          <div class="form-group">
            <label for="firstname" class="col-md-2 control-label">First Name</label>

            <div class="col-md-10">
              <input type="text" class="form-control" value="{{ $share->name }}" name="firstname" placeholder="First Name">
            </div>
          </div>

          <div class="form-group">
            <label for="lastname" class="col-md-2 control-label">Last Name</label>

            <div class="col-md-10">
              <input type="text" class="form-control" value="{{ $share->urls }}" name="lastname" placeholder="Last Name">
            </div>
          </div>

        
        </fieldset>
      </form>
     </div>
    </div>
  </div>

But i only want that it show me this one wich i have selected with the edit button on the index.view Here is the index view:

@extends('layout')

@section('content')
<style>
a:link{color:#000;}


  .uper {
    margin-top: 20px;
  
  }

  .card {
    width: 80%;
    float: right;
    background-color: #f7f7f7;
    margin-right: 50px;
  }

  .nav {
    width: 17%;
    float: left;
    background-color: #f7f7f7;
    height:80%;
    padding-top: 20px;
  padding-right: 20px;
  padding-bottom: 20px;
  padding-left: 20px;

  }

  .accordion {
    padding-top: 20px;
  padding-right: 20px;
  padding-bottom: 20px;
  padding-left: 20px;


  }


.navbar-expand-lg {

  padding-top: 20px;
  padding-right: 60px;
  padding-bottom: 20px;
  padding-left: 20px;
  height: 8%;
  border: 1px solid black;
}


</style>

<!-- Navigationsleiste -->

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="{{url('/')}}">IBP1 - Linkliste</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
      <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Link hinzufügen
</button>
      </li>
 </ul>

    <form class="form-inline my-2 my-lg-0" action="/search" method="post">
    {{ csrf_field() }}
      <input class="form-control mr-sm-2" name="search" type="search" placeholder="Suchen" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Suchen</button>
    </form>
  </div>
</nav>






<!-- Accordion  -->
<div class="accordion" id="accordionExample">
@foreach ($categories as $categorie)

@foreach ($shares as $share)
    <a href="{{route('shares.edit', $categorie->id)}}" inputtype="hidden" class="btn btn-default" action="{{$categorie->id}}" name="data-name" style="position: absolute;
        right: 20;"  ><i class="fas fa-edit"></i></a>
@endforeach


<div class="cars">
    <div class="card-header" id="headingSix">
      <h2 class="mb-0">
        <button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapse{{$categorie->id}}" aria-expanded="false" aria-controls="collapse{{$categorie->id}}" style="color: black">
        {{ $categorie->name}}
        </button>

        <!--
       <a href="{{ url('/edit') }}" class="btn btn-xs btn-info pull-right" input type="submit" value="{{$categorie->id}}" style="float: right; background-color: #3490dc">Edit</a>
        -->

      </h2>

    </div>
    <div id="collapse{{$categorie->id}}" class="collapse" aria-labelledby="heading{{$categorie->id}}" data-parent="#accordionExample">
      <div class="card-body">



    <!-- Einfügen der Daten in die Tabelle nach Kategorie ID -->
      @foreach($shares->where('categorie_id', $categorie->id) as $share)
     
 
      <a href='{{ $share->urls }}' style="color: black">{{ $share->name }}</a><br>


      <div>

      </div>
      @endforeach
      </div> 
    </div>
</div>       
        @endforeach
</div>





<!-- Modal Pushfenster Link hinzufügen -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Link hinzufügen:</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      
      <form method="post" action="{{ route('shares.store') }}">
      <div class="form-name">
              @csrf
              <label for="name">Link Name:</label>
              <input type="text" class="form-control" name="name"/>
          </div>
          <div class="form-adress">
              <label for="adress">Link Adresse:</label>
              <input type="text" class="form-control" name="urls"/>
              </div>
             
          <div class="form-kategorie">
              <label for="categorie">Kategorie:</label>
                   <option value='0' selected></option>
                   <select name='categorie_id' class='form-control'>
                                    <option value='0' selected></option>
                                    @foreach($categories as $categorie)
                                    <option value='{{ $categorie->id }}'>{{ $categorie->name }}</option>
                                    @endforeach
                                    </select>
                                       </div>
                                       <br>
                                       <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                       <button type="submit" class="btn btn-primary" action="{{ route('shares.store') }}">Hinzufügen</button>
                                       </form>
      <div class="modal-footer">
        
      </div>
    </div>
  </div>
</div>

Thats the web.php

Route::get('edit', '[email protected]');

An that is my [email protected]:

 public function edit(Request $request, $id)

    {
       
        $shares = Url::all();
        $categories = Categorie::all();        

        return view('edit', compact('shares'));
    }

Iam a absolutly beginner have read an whatch a lot in the internet. But i cant get the right solution :-( Thank you very much

Please sign in or create an account to participate in this conversation.