노출되는 이미지가 불편하시겠지만 양해를 구합니다. 노출, 클릭등에 관한 자료로 활용 중입니다.



Laravel(라라벨) 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


블로그 이미지

StartGuide

I want to share the basic to programming of each category and how to solve the error. This basic instruction can be extended further. And I have been worked in southeast Asia more than 3 years. And I want to have the chance to work another country.

,