connet.lolipop.jp
スタートページのレイアウト
スタートページになる、bladeページの作成です。以下のディレクトリに保存します。
resources/views/

・起動と同時にDBデータを表示
・登録/検索/更新/削除及びページネーションの機能を実装

index.blade.php
				      @extends('common')
				      @include('head')
				      @section('recdel_js')
				      <script type="text/javascript">
				      function recdelChk (id) {
				      	// 確認ダイアログ表示
				      	var id;
				      	var flag = confirm ("[ID="+id+"]番のデータを削除してもよろしいですか?\n\n削除したくない場合は[キャンセル]ボタンを押して下さい");
				      	// send_flg が TRUEなら送信、FALSEなら送信しない
				      	return flag;
				      }
				      </script>
				      @endsection
				      <style type="text/css">
				      	ul.pagination li {
				      		display: inline;
				      		font-size: 16px;
				      		font-weight: bold;
				      	}
				      	table td {
				      	padding:5px;
				      	}
				      </style>
				      
				      @include('header')
				      
				      @section('content_head')
				      <br />
				      <h2>■登録</h2>
				      <nav>   
				      	<ul style="position:relative;left:-12px;font-size:1.2rem;">
				      		<li><a href="/laravelSample/public/insert">データ追加</a></li>
				      	</ul>
				      </nav>
				      <br />
				      
				      <div>    
				      <br />
				      <h2>■検索</h2>
				      <br />
				      <!--Id--> 
				      <form method="get" action="/laravelSample/public/idsearch">       
				      	<input type="hidden" name="_token" value="{{csrf_token()}}"> 
				      	<label style="font-size:0.8rem;color:#440000;">・Id:</label>
				      	<input type="text" name="id" maxlength="7" value="{{session('id')}}" style="width:200px;height:25px;padding-left:5px;border:1px solid #ddd;">     
				      	<input type="submit" value="検索">
				      	<!--バリデーション-->
				      	<div style="color:#ff0000;">{{$errors->first('id')}}</div>
				      </form>  
				      
				      <!--NAME-->
				      <form method="get" action="/laravelSample/public/namesearch">    
				      	<input type="hidden" name="_token" value="{{csrf_token()}}">
				      	<label style="font-size:0.8rem;color:#440000;">・Name:</label>          
				      	<input type="text" name="name" maxlength="6" value="{{session('name')}}" style="width:200px;height:25px;padding-left:5px;border:1px solid #ddd;">
				      	<input type="submit" value="検索">
				      	<!--バリデーション-->
				      	<div style="color:#ff0000;">{{$errors->first('name')}}</div>    
				      </form>
				      </div><br />
				      <br />
				      @endsection
				      
				      @section('content')    
				      <h2>{{ session('msg') }}</h2>
				      <table border="1">
				      <thead>
				      	<tr><th><h3>Id</h3></th><th><h3>Name</h3></th><th><h3>Email</h3></th><th><h3>Tel</h3></th><th><h3>Memo</h3></th><th><h3>create</h3></th><th><h3>update</h3></th><th><h3>Edit</h3></th><th><h3>Del</h3></th></tr>
				      </thead>
				      <tbody>
				      @foreach($data as $val)    
				      <tr>
				      <td>{{ $val->id }}</td>    
				      <td>{{ $val->name }}</td>
				      <td>{{ $val->email }}</td>
				      <td>{{ $val->phone_number }}</td> 
				      <td><textarea readonly name="memo" cols="10" rows="1" style="overflow:auto;">{{ $val->memo }}</textarea></td>
				      <td>{{ $val->created_at }}</td>
				      <td>{{ $val->updated_at }}</td>
				      <td><a href="/laravelSample/public/update?id={{ $val->id }}">Edit</a></td>
				      <td><a href="/laravelSample/public/delete?id={{ $val->id }}" onclick="return recdelChk({{$val->id}});" style="color:#BF0000;">Del</a></td>
				      </tr>
				      @endforeach
				      </tbody>
				      </table>
				      <!--ページネーション-->
				      <div>
				      	<ul class="pagination">
				      		<li>{{ $data->appends(request()->only(['name']))->links() }}</li>
				      	</ul>
				      </div>
				      
				      <br />
				      
				      <div>
				      	<a href="/laravelSample/public/getIndex">{{ session('homeret') }}</a>
				      <div>
				      <br />
				      <hr>     
				      @endsection
				      @include('footer')
データ入力ページのレイアウト
name項目(カラム)の入力には、バリデーションを設定。

insert.blade.php
              @extends('common')
              @include('head')
              @include('header')
              @section('content')
              <br />
              <h2>登録</h2>
              <br />
              <form  method="post" action="/laravelSample/public/insert2">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <div>
                  <label>・Name:</label>
                  <input type="text" name="name" value="" style="width:200px;height:30px;border:1px solid #ddd;">
                  <span style="color:#ff0000;">{{$errors->first('name')}}</span>
                </div><br />              
                <div>
                  <label>・Email:</label>
                  <input type="text" name="email" value="{{old('email')}}" style="width:200px;height:30px;border:1px solid #ddd;">
                  </div><br />                
                <div>
                  <label style="margin-left:18px;">・Tel:</label>
                  <input type="text" name="phone_number" value="{{old('phone_number')}}" style="width:130px;height:30px;border:1px solid #ddd;">                  
                </div><br /> 
                <div>    
                  <label style="float:left;">・Memo:</label>
                  <textarea name="memo" cols="20" rows="5" style="overflow:auto;">{{ old('memo') }}</textarea>
                </div><br />          
                <div style="margin-left:60px;">
                  <input type="submit" value="追加">
                  <input type="reset" value="リセット">
                </div>
              </form>    
              <br /><br />
              <div>
                «<a href="/laravelSample/public/getIndex"> 戻る</a>
              <div><br />
              <hr>    
              @endsection
              @include('footer')
データ更新ページのレイアウト
memo項目(カラム)のみに、データの更新を設定。

update.blade.php
              @extends('common')    
              @include('head')
              @include('header') 
              @section('content')
              <br />
              <h2>■更新</h2> 
              <br />  
              <form method="post" action="/laravelSample/public/update">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input type="hidden" name="id" value="{{ $data->id }}">
                <div>
                  <label>・Id:</label>
                  <input type="text" name="id" disabled="disabled" value="{{ $data->id }}" style="width:100px;height:30px; padding-left:5px;border:1px solid #ddd;">
                </div>                     
                <br />              
                <div>
                  <label style="float:left;">・Memo:</label>               
                  <textarea name="memo" cols="20" rows="5" style="overflow:auto;">{{ $data->memo }}</textarea>             
                </div><br />                                
                <div style="margin-left:60px;">
                  <input type="submit" value="更新">
                </div>
              </form>
              <br /><br />
              <div>
                <a href="/laravelSample/public/getIndex">« 戻る</a>
              <div><br />
              <hr>    
              @endsection
              @include('footer')
Search
Google


↟ このページの先頭へ