0. 명령어 실행 하면, 아래 3가지가 자동으로 생성된다.
php artisan make:model Weaving -c -m
모델
C:\laravel\myLaravel8\myapp\app\ Weaving.php
컨트럴러
C:\laravel\myLaravel8\myapp\app\Http\WeavingController.php
데이터베이스의 테이블
database>migrations
2019_10_12_080203_create_Weaving_table.php 파일이 생성된다
1. 라우터 지정한다.
: 사용자가 127.0.0.1/index 로 들어올 경우, 특정 Controller@함수명의 내용을 불러온다.
Route::get('/index', 'WeavingController@index');
2. Controller :WeavingController.php
// Model을 부른다.
use App\Weaving;
class WeavingController extends Controller
{
//
public function index(){
// Weaving테이블에 있는 모든 내용을 불러온다.
$weavinglist = Weaving::all();
$weavinglist=Weaving::latest()->get();
$weavinglist=Weaving::orderBy('created_at', 'DESC')
->orderBy('packing', 'DESC')
->get();
//뷰페이지 weaving폴더.index.blade.php는 weavinglist라는 이름으로 값을 넘겨 받는다.
return view('weaving.index', [
'weavinglist' => $weavinglist
]);
}
}
3. Model : Weaving.php
class Weaving extends Model
{
//
protected $fillable = ['title', 'size','machine','packing','wiggle', 'color','qty','memo','created_at','cat'];
}
4. View : weaving.index
@extends('layouts.index')
@section('title')
about
@endsection
@section('content')
<thead>
<tr>
<th>Title</th>
<th>Size</th>
<th>Machine</th>
<th>Wiggle</th>
<th>Color</th>
<th>Q'ty</th>
</tr>
</thead>
@foreach($weavinglist as $weavinglist)
<tbody>
<tr>
<td>{{ $weavinglist->title }}</td>
<td>{{ $weavinglist->size }}</td>
<td>{{ $weavinglist->machine }}</td>
<td>{{ $weavinglist->wiggle }}</td>
<td>{{ $weavinglist->color }}</td>
<td>{{ $weavinglist->qty }}</td>
<td>
<div class="form-group">
<a href="/weavings/{{ $weavinglist->id }}">
<button type="submit" class="btn btn-primary">View</button>
</a>
</div>
</td>
</tr>
</tbody>
@endforeach
@endsection
** 라라벨 문법
<?php echo ?> 라라벨에선 {{ }}이렇게 표현한다.
<?php foreach ($books as book) ?> 라라벨에서 @foreach ($books as book)
'BackEND > Laravel' 카테고리의 다른 글
CRUD 라라벨에서 글보기 (0) | 2020.11.03 |
---|---|
CRUD 라라벨에서 글 저장하기 2 (0) | 2020.11.02 |
CRUD 라라벨에서 글 저장하기 1 (0) | 2020.11.02 |
라라벨에서 컨트롤,모델,테이블을 생성하는방법 (0) | 2020.11.01 |
라라벨 중요한 파일들. (0) | 2020.11.01 |