Laravel 5.3(라라벨), Layouts, CSS & JS Part 1 , Part 2 , Form Post
Web Tech./PHP, Web 2017. 1. 6. 19:45Laravel(라라벨) 5.3,
Layouts, CSS & JS Part 1
Layout를 사용해서 파일이나 페이지에 포함되도록 끼워 넣는 방법과 JS파일을 연결하는 방법을 정리한다.
1. 기본 Layout 폴더와 페이지를 만들기
위치 : reources\views\layout\layouts.blade.php
<!DOCTYPE HTML>
<html>
<head>
<title>
@yield('title') Page
</title>
</head>
<body>
@yield('content')
</body>
@stack('scripts')
{!! Html::script('js/hello.js') !!}
</html>
1.1 public/js/hello.js
alert('Hello World!!');
2. laravelcollective/html 설치하기
> composer require laravelcollective/html
2.1 laravelcollective/html 등록하기
위치 : config/app.php
'providers' => [ Collective\Html\HtmlServiceProvider::class, ],
'aliases' => [ 'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class, ],
3. View 페이지 ( Blade Template PHP ) 작성 하기
위치 : resources/views/pages/hello.blade.php
@extends('layout.layouts')
@section('title','Hello World')
@section('content')
My name is Henrio !!!
@endsection
@push('scripts')
{!! Html::script('js/hello2.js') !!}
@endpush
2.1 public/js/hello2.js
alert('Hello, Hello, It's ME.');
동영상 강좌 : https://www.youtube.com/watch?v=Xza0wUFJC3M&index=3&list=PL-4_JsMSrLiqrzQ36KwYVn4uCjYLiAd_C
Laravel(라라벨) 5.3 ,
Layouts, CSS & JS Part 2
1. download Bootstrap
copy folder to /public with name of 'bootstrap'
2. include css to layouts.blade.php
<head>
{!! Html::style('bootstrap/css/bootstrap.min.css')!!}
</head>
3. add form code to hello.blade.php
@section('content')
<div class="container">
<div class="row">
<h4>Hello World! Henrio</h4>
<hr/>
</div>
<div class="row">
<div class="container">
{!! Form::open( ['url' => '', 'method' => 'POST',
'class' => 'form-horizontal'] ) !!}
{!! Form::token() !!}
<div class="row">
<div class="col-sm-2 center-block">
{!! Form::label('text','Insert Your Text Here!',
['class' => 'control-label pull-right']) !!}
</div>
<div class="col-sm-4 center-block">
{!! Form::text('text','',
['class' => 'form-control pull-left']) !!}
</div>
<div class="col-sm-6 center-block">
</div>
</div> <!-- class row -->
<div class="row">
</div> <!-- class row -->
<div class="row">
<div class="col-sm-6 center-block">
{!! Form::submit('Submit The Input',
['id' =>'btn-stmt','class' => 'btn btn-info pull-right']) !!}
</div>
<div class="col-sm-6 center-block">
</div>
</div> <!-- class row -->
{!! Form::close() !!}
</div> <!-- class container -->
</div> <!-- class row -->
</div> <!-- class container -->
@endsection
4. create styles.css under css folder
#btn-sbmt {
position:relative;
margin-top:50px;
}
5. add styles.css to layouts.blade.php
<head>
{!! Html::style(css/styles.css')!!}
</head>
동영상 강좌 : https://www.youtube.com/watch?v=PS-Yr8CRI1o&index=4&list=PL-4_JsMSrLiqrzQ36KwYVn4uCjYLiAd_C
Laravel(라라벨) 5.3,
Forms And Working With Models
1. Create Controller & Model , MySQL Table
> php artisan make:controller TextController
> php artisan make:model Posts
> create table (
id int not null auto_increment primary key,
posts text,
)
2. Modify Code for model at app/Posts.php
class Posts extends Model
{
//
public $timestamps = false;
protected $table = "posts";
protected $primaryKey = "ID";
protected $casts = ["ID" => "INT"];
}
3. Modify Code for controller at app/Http/Controllers/TextController.php
public function submitted(Request $request) {
$text = $request->get('text');
echo $text;
}
4. Add router to routes/web.php
Route::post('submitted','TextController@submitted');
5. Add post url at resource/views/pages/hello.blade.php
{!! Form::open( ['url' => '/submitted', 'method' => 'POST',
'class' => 'form-horizontal'] ) !!}
{!! Form::token() !!}
Test access and check the result : http://[hosturl]:8000/hello
6. Modify code to save at app/Http/Controllers/TextController.php
$text = $request->get('text');
//echo $text;
$posts = new Posts();
$posts->Posts = $text;
// save
$posts->save();
동영상 강좌 : https://www.youtube.com/watch?v=OgbUlgSwl-o&index=5&list=PL-4_JsMSrLiqrzQ36KwYVn4uCjYLiAd_C
관련된 이전 글 : Laravel 5.3 , Routes & Controllers for MVC ( Model View Controller )
- Controller 와 View 수정을 위한 위치등을 참조...
http://printhelloworld.tistory.com/admin/entry/post/?id=76
'Web Tech. > PHP, Web' 카테고리의 다른 글
2.October CMS , Basic Concepts ( 기본 개념 ) (0) | 2017.01.18 |
---|---|
OctoberCMS를 Laravel(라라벨) Homestead에 설치 (0) | 2017.01.12 |
Laravel(라라벨) 5.3, Routes & Controllers for MVC (0) | 2017.01.06 |
Laravel(라라벨) Homestead 사용하기 (0) | 2016.12.19 |
Laravel(라라벨) 기초 ( 5.0 ~ 5.3 ) (0) | 2016.12.15 |