PHP Laravel 6 – CRUD 기본 : 목록 , 확인 (3) 

– 목록 화면 ( 편집 파일 : TestCRUDController )

publicfunctionindex()

    {

$test = TestCRUD::all();

return view(‘test_view.index’, compact(‘test’));

    }

– View 파일 생성 ( /resources/views/test_view )  index.blade.php

@extends(‘layout’)

@section(‘content’)

<style>

.uper {

margin-top: 40px;

  }

</style>

<divclass=”uper”>

<divclass=”card-header”>

<h1>List test crud</h1>

</div>

  @if(session()->get(‘success’))

<divclass=”alert alert-success”>

      {{ session()->get(‘success’) }}  

</div><br/>

  @endif

<tableclass=”table table-striped”>

<thead>

<tr>

<td></td>

<td>Title</td>

<td>description</td>

<tdcolspan=”2″>기능</td>

</tr>

</thead>

<tbody>

    @foreach($test as $column)

<tr>

<td>{{$column->id}}</td>

<td>{{$column->title}}</td>

<td>{{$column->description}}</td>

<td></td>

<td></td>

</tr>

        @endforeach

</tbody>

</table>

</table>

<div>

@endsection

– 확인 : 목록(메인) 화면

– 목록 “기능”  항목에 버튼 “확인” , “수정”, “삭제” 를 넣는다.

> 파일 편집 (TestCRUDController )

publicfunctionshow($id)

    {

$test = TestCRUD::find($id);

returnview(‘test_view.view’, compact(‘test’));

    }

> 파일 생성 ( /resources/views/test_view ) view.blade.php

@extends(‘layout’)

@section(‘content’)

<style>

.uper {

margin-top: 40px;

  }

</style>

<divclass=”card uper”>

<divclass=”card-header”>

    View – Test C.R.U.D 

</div>

<divclass=”card-body”>

    @if ($errors->any())

<divclass=”alert alert-danger”>

<ul>

            @foreach ($errors->all() as $error)

<li>{{ $error }}</li>

            @endforeach

</ul>

</div><br/>

    @endif

<divclass=”form-group”>

<labelfor=”name”>Title:</label>

                {{ $test->title }}

</div>

<divclass=”form-group”>

<labelfor=”iurl”>Description :</label>

              {{ $test->description }}

</div>

<ahref=”{{ route(‘test_crud.index’)}}”class=”btn btn-primary”>목록</a>

</div>

</div>

– 편집 ( index.blade.php ) 

<tableclass=”table table-striped”>

<thead>

<tr>

<td></td>

<td>Title</td>

<td>description</td>

<tdcolspan=”3″>기능</td>

</tr>

</thead>

<tbody>

    @foreach($test as $column)

<tr>

<td>{{$column->id}}</td>

<td>{{$column->title}}</td>

<td>{{$column->description}}</td>

<td><a href=”{{ route(‘test_crud.show’, $column->id)}}” class=”btn btn-primary”>확인</a></td>

<td></td>

<td></td>

</tr>

        @endforeach

</tbody>

</table>

– 확인 : 웹 화면에서 확인 

> http://도메인/test_crud

> 위 화면에서 “확인” 버튼을 누르면 아래와 같이 됨.

소스 : https://github.com/nzhongtting/Laravel_hsh_board

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다