2017-01-31 4 views
0

데이터베이스에 웹 사이트라는 테이블이 있습니다.laravel blade - 변수가 정의되지 않았습니다.

그 내부

나는 두 개의 필드가 있습니다

이름 = 값 "이름" HTML = (해당 필드에 저장된 전체 HTML 코드)와를 그래서 내가하고 싶은 순간

은 다음과 같습니다

나는 데이터베이스에서 변수와 내가 공격 후에는 다음과 같습니다 그래서 그 이름에 assosiated 필드 HTML에서 실제 렌더링 된 HTML 페이지를 표시 할 입력 브라우저의 로컬 호스트/웹 사이트/이름으로 입력 한 경우 :

<!DOCTYPE html> 

<html> 
<head> 
    <title>Template 1</title> 
     <link href="http://localhost/templates/css.css" rel="stylesheet" type="text/css"> 
</head> 
<body> 
    <div class="logo"> 
     <img class="images" id="image" src="#" alt="Your Logo"/> 
    </div> 
<div contenteditable="true" id="content" class="draggable ui-widget-content refresh"><p>Change Text inside this box</p></div> 

<div id ="editTxt" class="refresh" contenteditable="true"> 
<p>This text can be by the user.</p> 
</div> 
</body> 
</html> 

분명히 코드는 아니지만 실제 페이지를보고 싶습니다. 어떻게 할 수 있습니까?

website.blade.php :

@extends('layouts.master') @section('title', 'Website Builder') @section('content') 
<meta name="csrf-token" content="{{ csrf_token() }}" /> 


{{html_entity_decode($website->html)}} 


</html> 
@endsection @show 

경로 :

Route::get('website/{name}', '[email protected]'); 

컨트롤러 :

function websites($name) 
{ 
    $websites = Website::find($name); 
    return view('layouts/website'); 
} 

그리고 현재의 에러 메시지 (이 오류 경우 페이지를 표시 할이 코드를 가정 고정)

정의되지 않은 변수 : 웹 사이트 (보기 : C : \ XAMPP \ htdocs를 \ fyproject \ 리소스 \ 전망 \ 레이아웃 \ website.blade.php)

그래서 기본적으로 값 '이름'=> '널 (null)'와 내 데이터베이스에서 그렇게 된 이유는 무엇입니까?

답변

1

당신은이 문제를 해결하기 위해 뷰에 변수를 전달해야

$websites = Website::find($name); 
return view('layouts/website', ['websites' => $websites]); 

또는 :

$websites = Website::find($name); 
return view('layouts/website', compact('websites'));