아래와 같이 입력해도 

xcode-select --install


아래와 같이 뜬다

xcode-select: error: command line tools are already installed, use "Software Update" to install updates


아래와 같이 명령어를 입력하자 커맨드라인 툴삭제 

sudo rm -rf /Library/Developer/CommandLineTools


그리고 재설치 한다.

xcode-select --install


1 web.php 주소는  json api 데이터는 http://jsonplaceholder.typicode.com/ 여기서 가지고 온다.

<?php

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
$response = Http::get('http://jsonplaceholder.typicode.com/todos/1');
// return view('welcome',[
// 'info' => '안녕하세요 저는 인포입니다.'
// ]);
dd($response->json());
});


/vendor/laravel/framework/src/illuminate/Http/Client/Response.php 파일을 열어보면

응답 메서드를 정의한 것을 볼 수 있다.



dd($response->body());

dd($response->headers());

dd($response->header('Date'));


dd($response->status());


dd($response->effectiveUri());


dd($response->ok());



결과



<?php

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
$response = Http::post('http://jsonplaceholder.typicode.com/posts',[
'userId' => 123
]);

if($response->offsetExists('userId')){
dd($response['userId']);
}

});


1. php artisan make:component Navigation --inline


app/View/Components/Navigation/php 파일만 생성된다.


2. 만들어진 component를 삽입해보자

<body class="flex flex-col items-center">

<x-sidebar title="My Sidebar" :info="$info" class="bg-gray-500">

<x-slot name="sometning">사이드바 제목</x-slot>

<div class="border-solid border-4 border-red-500">추가내용</div>

</x-sidebar>

<x-navigation></x-navigation>

</body>


결과


1. welcome.blade.php

<x-sidebar title="My Sidebar" :info="$info" class="bg-gray-500">

<x-slot name="sometning">사이드바 제목</x-slot>

<div class="border-solid border-4 border-red-500">추가내용</div>

</x-sidebar>


2. 

<div {{$attributes->merge(['class' => 'text-xl'])}}>

<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
<h2>{{ $sometning }}</h2>
<p class="text-pink-200">Hello Laravel 7 Component</p>

<ul class="list-disc">
@foreach($list('저는 리스트 매개변수입니다') as $item)
<li>{{ $item }}</li>
@endforeach
</ul>

{{ $slot }}

</div>


결과


'라라벨 > laravel7스터디' 카테고리의 다른 글

GuzzleHttp 사용하기  (0) 2020.03.28
인라인 뷰를 렌더링하는 컴포넌트 생성  (0) 2020.03.28
component에 추가내용 전달하기  (0) 2020.03.28
tailwindcss cdn 적용  (0) 2020.03.28
리스트 불러오기  (0) 2020.03.28

1. welcome.blade.php <div>추가내용</div>을 추가한다.

<body class="flex flex-col items-center">

<x-sidebar title="My Sidebar" :info="$info" class="bg-gray-500">

<div class="border-solid border-4 border-red-500">추가내용</div>

</x-sidebar>

</body>


2. sidebar.blade.php  삽입할 곳에 {{ $slot }} 를 입력한다.

<div {{$attributes->merge(['class' => 'text-xl'])}}>

<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
<p class="text-pink-200">Hello Laravel 7 Component</p>

<ul>
@foreach($list('저는 리스트 매개변수입니다') as $item)
<li>{{ $item }}</li>
@endforeach
</ul>

{{ $slot }}

</div>


결과


1. welcome.blade.php <head>안에 삽입</head>

<!-- TailWindCss -->
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">


2. body 중앙정렬한다. 

sidebar컴포넌트 배경을 그레이500으로 적용한다.

<body class="flex flex-col items-center">

<x-sidebar title="My Sidebar" :info="$info" class="bg-gray-500"/>

</body>


3. div에 $attributes를 넘겨줘야 적용이된다.

<div {{$attributes}}>

<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component<br>

@foreach($list('저는 리스트 매개변수입니다') as $item)
<ul>
{{ $item }}
</ul>
@endforeach

</div>


결과


4. div에 텍스트 크기 정의하기

<div {{$attributes->merge(['class' => 'text-xl'])}}>

<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
<p class="text-pink-200">Hello Laravel 7 Component</p>

@foreach($list('저는 리스트 매개변수입니다') as $item)
<ul>
{{ $item }}
</ul>
@endforeach

</div>


결과




1. Sidebar.php  파일에서 list() 메서드를 추가한다.

public function list()
{
return[
'hi',
'hello',
'apple'
];
}


2. render() 컴포넌트에 list() 메서드를  붙인다. (생략이 가능하다)

public function render()
{
return view('components.sidebar',[
'list' => $this->list()
]);
}


3. sedebar.blade.php  list 루프를 돌려준다.

<div>
<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component<br>

@foreach($list as $item)
<ul>
{{ $item }}
</ul>
@endforeach

</div>


결과


4. Sidebar.php 매개변수 넘기기

public function list($string)
{
return[
'hi',
'hello',
'apple',
$string
];
}


5. sidebar.blade.php $list() 매개변수를 넣어준다.

<div>
<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component<br>

@foreach($list('저는 리스트 매개변수입니다') as $item)
<ul>
{{ $item }}
</ul>
@endforeach

</div>


결과


1. web.php

Route::get('/', function () {
return view('welcome',[
'info' => '안녕하세요 저는 인포입니다.'
]);
});


2. welcome.blade.php

<x-sidebar title="My Sidebar" :info="$info"/>


3. Sidebar.php  info항목 추가

<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Sidebar extends Component
{
public $title;
public $info;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct($title, $info)
{
$this->title = $title;
$this->info = $info;
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('components.sidebar');
}
}


4. sidebar.blade.php {{ $info }} 변수 추가입력

<div>
<h1>{{ $title }}</h1>
<h3>{{ $info }}</h3>
Hello Laravel 7 Component
</div>


결과


'라라벨 > laravel7스터디' 카테고리의 다른 글

component에 추가내용 전달하기  (0) 2020.03.28
tailwindcss cdn 적용  (0) 2020.03.28
리스트 불러오기  (0) 2020.03.28
타이틀 정의하는 방법  (0) 2020.03.28
블레이드(blade)새로운 구성법 component  (0) 2020.03.28

+ Recent posts