편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
10번째 줄: | 10번째 줄: | ||
Laravel의 기본 기능들을 샘플로 다루어 보기 위해, 태스크들을 다루는 태스크 목록 애플리케이션을 만들어 보겠습니다. 즉, 전형적인 "할 일" 목록 예제를 다루게 됩니다. 이 프로젝트의 완성된 소스코드는 [https://github.com/laravel/quickstart-basic GitHub에서 확인]할 수 있습니다. | Laravel의 기본 기능들을 샘플로 다루어 보기 위해, 태스크들을 다루는 태스크 목록 애플리케이션을 만들어 보겠습니다. 즉, 전형적인 "할 일" 목록 예제를 다루게 됩니다. 이 프로젝트의 완성된 소스코드는 [https://github.com/laravel/quickstart-basic GitHub에서 확인]할 수 있습니다. | ||
== | ==도커 환경== | ||
<syntaxhighlight lang='console'> | <syntaxhighlight lang='console'> | ||
testuser@lcoalhost:~$ mkdir ~/workspace && cd ~/workspace | |||
testuser@localhost:~/workspace$ docker run --name laravel --rm -it -v ${PWD}:/workspace -w /workspace --entrypoint="" --network host bitnami/laravel:latest bash | |||
Unable to find image 'bitnami/laravel:latest' locally | Unable to find image 'bitnami/laravel:latest' locally | ||
latest: Pulling from bitnami/laravel | latest: Pulling from bitnami/laravel | ||
28번째 줄: | 19번째 줄: | ||
Digest: sha256:d16af27a0d4c2f6f3f71c730d7def97de91e0b2ea0233e84dc758340521b1629 | Digest: sha256:d16af27a0d4c2f6f3f71c730d7def97de91e0b2ea0233e84dc758340521b1629 | ||
Status: Downloaded newer image for bitnami/laravel:latest | Status: Downloaded newer image for bitnami/laravel:latest | ||
root@ | root@localhost:/workspace# | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | ==설치== | ||
환경이 준비되면 Composer를 사용하여 Laravel 프레임워크를 설치할 수 있습니다: | 우선, Laravel 프레임워크을 새로 설치해야 합니다. [[Laravel Homestead|Homestead 가상머신]]을 사용하거나 선택한 로컬 PHP 환경을 사용하여 프레임워크를 실행할 수 있습니다. 로컬 환경이 준비되면 Composer를 사용하여 Laravel 프레임워크를 설치할 수 있습니다: | ||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
39번째 줄: | 30번째 줄: | ||
<syntaxhighlight lang='console'> | <syntaxhighlight lang='console'> | ||
root@ | root@localhost:/workspace# composer create-project laravel/laravel quickstart --prefer-dist | ||
Creating a "laravel/laravel" project at "./quickstart" | Creating a "laravel/laravel" project at "./quickstart" | ||
Installing laravel/laravel (v11.1.1) | Installing laravel/laravel (v11.1.1) | ||
54번째 줄: | 45번째 줄: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang='console'> | <syntaxhighlight lang='console'> | ||
root@ | root@localhost:/workspace# cd quickstart/ | ||
root@ | root@localhost:/workspace/quickstart# find app/ routes/ resources/ | grep .php | ||
app/Providers/AppServiceProvider.php | app/Providers/AppServiceProvider.php | ||
app/Http/Controllers/Controller.php | app/Http/Controllers/Controller.php | ||
62번째 줄: | 53번째 줄: | ||
routes/web.php | routes/web.php | ||
resources/views/welcome.blade.php | resources/views/welcome.blade.php | ||
</syntaxhighlight> | </syntaxhighlight> | ||
'''참고''': [[composer create-project laravel/laravel quickstart --prefer-dist]] | '''참고''': [[composer create-project laravel/laravel quickstart --prefer-dist]] | ||
==데이터베이스 준비== | ==데이터베이스 준비== | ||
99번째 줄: | 69번째 줄: | ||
$ php artisan make:migration create_tasks_table --create=tasks | $ php artisan make:migration create_tasks_table --create=tasks | ||
INFO Migration [database/migrations/ | INFO Migration [database/migrations/2024_06_15_161234_create_tasks_table.php] created successfully. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
마이그레이션 파일은 프로젝트의 <code>database/migrations</code> 디렉토리에 생성됩니다. 아마도 <code>make:migration</code> 명령어가 이미 자동 증가 ID와 타임스탬프를 마이그레이션 파일에 추가한 것을 보셨을 것입니다. 이 파일을 편집하여 작업 이름을 위한 <code>name</code> 문자열 컬럼을 추가해봅시다: | 마이그레이션 파일은 프로젝트의 <code>database/migrations</code> 디렉토리에 생성됩니다. 아마도 <code>make:migration</code> 명령어가 이미 자동 증가 ID와 타임스탬프를 마이그레이션 파일에 추가한 것을 보셨을 것입니다. 이 파일을 편집하여 작업 이름을 위한 <code>name</code> 문자열 컬럼을 추가해봅시다: | ||
{{소스헤더|database/migrations/ | {{소스헤더|database/migrations/2024_06_15_161234_create_tasks_table.php}} | ||
<syntaxhighlight lang='php' highlight='16'> | <syntaxhighlight lang='php' highlight='16'> | ||
<?php | <?php | ||
146번째 줄: | 116번째 줄: | ||
INFO Running migrations. | INFO Running migrations. | ||
2024_06_15_161234_create_tasks_table ....................................... 9.24ms DONE | |||
</syntaxhighlight> | </syntaxhighlight> | ||
251번째 줄: | 221번째 줄: | ||
<head> | <head> | ||
<title>Laravel Quickstart - Basic</title> | <title>Laravel Quickstart - Basic</title> | ||
< | |||
<!-- CSS And JavaScript --> | |||
</head> | </head> | ||
<body> | <body> | ||
< | <div class="container"> | ||
< | <nav class="navbar navbar-default"> | ||
<!-- Navbar Contents --> | |||
</ | </nav> | ||
</ | </div> | ||
@yield('content') | @yield('content') | ||
280번째 줄: | 251번째 줄: | ||
<!-- Bootstrap Boilerplate... --> | <!-- Bootstrap Boilerplate... --> | ||
<div class="panel-body"> | |||
<!-- Display Validation Errors --> | |||
@include('common.errors') | |||
<!-- New Task Form --> | |||
<form action="{{ url('task') }}" method="POST" class="form-horizontal"> | |||
{{ csrf_field() }} | |||
<!-- | <!-- Task Name --> | ||
< | <div class="form-group"> | ||
<label for="task" class="col-sm-3 control-label">Task</label> | |||
<div class="col-sm-6"> | |||
<div class=" | <input type="text" name="name" id="task-name" class="form-control"> | ||
<input type="text" name="name" id="task" class="form-control"> | |||
</div> | </div> | ||
</div> | |||
<!-- Add Task Button --> | |||
<button type="submit" class="btn btn- | <div class="form-group"> | ||
<div class="col-sm-offset-3 col-sm-6"> | |||
</ | <button type="submit" class="btn btn-default"> | ||
</ | <i class="fa fa-plus"></i> Add Task | ||
</ | </button> | ||
</div> | |||
</div> | |||
</form> | |||
</div> | </div> | ||
335번째 줄: | 308번째 줄: | ||
{{소스헤더|routes/web.php}} | {{소스헤더|routes/web.php}} | ||
<syntaxhighlight lang='php'> | <syntaxhighlight lang='php'> | ||
Route::post('/task', function () { | Route::post('/task', function (Request $request) { | ||
$validator = Validator::make( | $validator = Validator::make($request->all(), [ | ||
'name' => 'required|max:255', | 'name' => 'required|max:255', | ||
]); | ]); | ||
380번째 줄: | 353번째 줄: | ||
{{소스헤더|routes/web.php}} | {{소스헤더|routes/web.php}} | ||
<syntaxhighlight lang='php' highlight='12-16'> | <syntaxhighlight lang='php' highlight='12-16'> | ||
Route::post('/task', function () { | Route::post('/task', function (Request $request) { | ||
$validator = Validator::make( | $validator = Validator::make($request->all(), [ | ||
'name' => 'required|max:255', | 'name' => 'required|max:255', | ||
]); | ]); | ||
392번째 줄: | 365번째 줄: | ||
$task = new Task; | $task = new Task; | ||
$task->name = | $task->name = $request->name; | ||
$task->save(); | $task->save(); | ||
434번째 줄: | 407번째 줄: | ||
<!-- Current Tasks --> | <!-- Current Tasks --> | ||
@if (count($tasks) > 0) | @if (count($tasks) > 0) | ||
<div class=" | <div class="panel panel-default"> | ||
<div class=" | <div class="panel-heading"> | ||
Current Tasks | Current Tasks | ||
</div> | </div> | ||
<div class=" | <div class="panel-body"> | ||
<table class="table table-striped"> | <table class="table table-striped task-table"> | ||
<!-- Table Headings --> | <!-- Table Headings --> | ||
480번째 줄: | 453번째 줄: | ||
<tr> | <tr> | ||
<!-- Task Name --> | <!-- Task Name --> | ||
<td> | <td class="table-text"> | ||
{{ $task->name }} | <div>{{ $task->name }}</div> | ||
</td> | </td> | ||
491번째 줄: | 464번째 줄: | ||
<button type="submit" class="btn btn-danger"> | <button type="submit" class="btn btn-danger"> | ||
Delete | <i class="fa fa-trash"></i> Delete | ||
</button> | </button> | ||
</form> | </form> |