2017-12-16 7 views
2

私は伸ばしたい2種類のレイアウトファイルがあります。ラーベールの刃の延長内に

app.blade.phpが主なレイアウトです:ここに私のフォームコードです

<div class="container h-100"> 
    <div class="row h-100 justify-content-center align-items-center"> 
     <div class="col-6"> 
      <div class="card"> 
       <div class="card-body"> 
        @yield('content') 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

<!DOCTYPE html> 
<html lang="{{ app()->getLocale() }}"> 
<head> 
    <!-- Meta --> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 
    <meta name="csrf-token" content="{{ csrf_token() }}"> 

    <title>@yield('title') | {{ config('app.name') }}</title> 

    <!-- Styles --> 
    <link rel="stylesheet" href="{{ asset('laraback/css/bootstrap.min.css') }}"> 
    <link rel="stylesheet" href="{{ asset('laraback/css/fontawesome.min.css') }}"> 
    <link rel="stylesheet" href="{{ asset('laraback/css/datatables.min.css') }}"> 
</head> 
<body> 

@yield('content') 

<!-- Scripts --> 
<script src="{{ asset('laraback/js/jquery.min.js') }}"></script> 
<script src="{{ asset('laraback/js/popper.min.js') }}"></script> 
<script src="{{ asset('laraback/js/bootstrap.min.js') }}"></script> 
@stack('scripts') 

</body> 
</html> 

form.blade.php私が使用したい子のレイアウトされ

@section('content') 
    <form method="POST" action="{{ route('login') }}" novalidate> 
     {{ csrf_field() }} 

     <div class="form-group"> 
      <label for="email">Email</label> 
      <input type="email" name="email" id="email" class="form-control"> 
     </div> 

     <div class="form-group"> 
      <label for="password">Password</label> 
      <input type="password" name="password" id="password" class="form-control"> 
     </div> 

     <div class="form-check"> 
      <label class="form-check-label"> 
       <input type="checkbox" name="remember" class="form-check-input"> 
       Remember 
      </label> 
     </div> 

     <button type="submit" class="btn btn-primary">Login</button> 
     <a class="btn btn-link" href="{{ route('password.email') }}">Forgot Your Password?</a> 
    </form> 
@endsection 

私が知っている私は、 @extends('layouts.app')を使用してメインレイアウトのフォームを取得できますが、どうすればできますかそれでform.blade.phpapp.blade.phpの中に広げることができますか? (私はこれが混乱していると思います)。 app.blade.phpで

<!DOCTYPE html> 
<html lang="{{ app()->getLocale() }}"> 
<head> 
    <!-- Meta --> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 
    <meta name="csrf-token" content="{{ csrf_token() }}"> 

    <title>@yield('title') | {{ config('app.name') }}</title> 

    <!-- Styles --> 
    <link rel="stylesheet" href="{{ asset('laraback/css/bootstrap.min.css') }}"> 
    <link rel="stylesheet" href="{{ asset('laraback/css/fontawesome.min.css') }}"> 
    <link rel="stylesheet" href="{{ asset('laraback/css/datatables.min.css') }}"> 
</head> 
<body> 

<div class="container h-100"> 
    <div class="row h-100 justify-content-center align-items-center"> 
     <div class="col-6"> 
      <div class="card"> 
       <div class="card-body"> 
        <form method="POST" action="{{ route('login') }}" novalidate> 
         {{ csrf_field() }} 

         <div class="form-group"> 
          <label for="email">Email</label> 
          <input type="email" name="email" id="email" class="form-control"> 
         </div> 

         <div class="form-group"> 
          <label for="password">Password</label> 
          <input type="password" name="password" id="password" class="form-control"> 
         </div> 

         <div class="form-check"> 
          <label class="form-check-label"> 
           <input type="checkbox" name="remember" class="form-check-input"> 
           Remember 
          </label> 
         </div> 

         <button type="submit" class="btn btn-primary">Login</button> 
         <a class="btn btn-link" href="{{ route('password.email') }}">Forgot Your Password?</a> 
        </form> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

<!-- Scripts --> 
<script src="{{ asset('laraback/js/jquery.min.js') }}"></script> 
<script src="{{ asset('laraback/js/popper.min.js') }}"></script> 
<script src="{{ asset('laraback/js/bootstrap.min.js') }}"></script> 
@stack('scripts') 

</body> 
</html> 

答えて

0

をあなたのコードのように@yield(「コンテンツ」)を使用することができます。

これは私が望む結果の一例です。 app.blade.phpは完璧です。

あなたのform.blade.phpに下記のように修正してください。

@extends('layouts.app') 
@section('content') 
<div class="container h-100"> 
    <div class="row h-100 justify-content-center align-items-center"> 
     <div class="col-6"> 
      <div class="card"> 
       <div class="card-body"> 
        @include('form_content') 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

@endsection 

そして、@sectionと@endsectionを使わずにフォームの内容をform_content.blade.phpファイルにする必要があります。

<form method="POST" action="{{ route('login') }}" novalidate> 
    {{ csrf_field() }} 

    <div class="form-group"> 
     <label for="email">Email</label> 
     <input type="email" name="email" id="email" class="form-control"> 
    </div> 

    <div class="form-group"> 
     <label for="password">Password</label> 
     <input type="password" name="password" id="password" class="form-control"> 
    </div> 

    <div class="form-check"> 
     <label class="form-check-label"> 
      <input type="checkbox" name="remember" class="form-check-input"> 
      Remember 
     </label> 
    </div> 

    <button type="submit" class="btn btn-primary">Login</button> 
    <a class="btn btn-link" href="{{ route('password.email') }}">Forgot Your Password?</a> 
</form> 

次に、結果ページが必要に応じて表示されます。

@ifを使用して@include句を分類できます。 これは、@includeごとに条件節を作成できることを意味します。 条件が収まる場合は、@includeセクションのうちの1つを含めることができます。

+0

このソリューションでは、同じフォームを表示するために2つの異なるファイルを作成する必要があります。 – kjdion84

+0

2つの異なるファイルを意味しますか? – HiKangg

+0

'@ include'は毎回異なるので、子レイアウトで使用したいフォームごとに別々の' form.blade.php'ファイルを作成する必要があります。 – kjdion84