0

I have a table in my database called websites.

Inside it I have two fields:

name = with value "name" html = (whole html code stored in that field)

So at the moment what I want to do is:

If I type into a browser localhost/website/name which is the variable from database and after I hit enter I want to display actual rendered html page from a field html assosiated to that name so it looks like this:

<!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>

Obviously I don't want to see the code but the actual page. How can that be done?

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:

Route::get('website/{name}', 'BuilderController@websites');

Controller:

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

And current error message (assuming this code will display the page if this error is fixed)

Undefined variable: website (View: C:\xampp\htdocs\fyproject\resources\views\layouts\website.blade.php)

So basically value 'name' => 'null' and in my database it isn't so why is this happening?

1 Answer 1

1

You need to pass the variable to the view to fix this:

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

Or:

$websites = Website::find($name);
return view('layouts/website', compact('websites'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.