0

I will try to keep it simple in database I have 2 fields, name = name of site and html = html code of that site.

Database looks like this:

UPDATE `websites` SET `name` = 'name', `html` = ' <title>Template 1</title> <link href="http://localhost/templates/css.css" rel="stylesheet" type="text/css"> <div class="logo"> <img class="images" id="image" src="#" alt="Your Logo"> </div> <div contenteditable="true" id="content" class="draggable ui-widget-content refresh ui-draggable ui-draggable-handle" style="position: relative; left: 209px; top: 139px;"><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> ' WHERE `websites`.`id` = 1;

Now when I type into browser localhost/website/{name} I would like to append html code from that database into a browser using ajax.

I have started something like this:

Controller:

function websites($name)
    {
        $websites = Website::all();
        return view('layouts/website', ['websites' => $websites]);
        $name = $websites->name;
    }

Route:

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

website.blade.php:

@extends('layouts.master') @section('title', 'Website Builder') @section('content')
<meta name="csrf-token" content="{{ csrf_token() }}" />
<div class="container template_class ">
    @foreach ($websites as $website)
    <a class="content-link" href="{{ asset($website->name )}}">
        <img src="{{ asset($website->html )}}"/>
        </a> @endforeach

</div>
</body>
<link href="{{asset('css/bootstrap-colorpicker.min.css')}}" rel="stylesheet" type="text/css">
<link href="{{asset('css/bootstrap-formhelpers.min.css')}}" rel="stylesheet" type="text/css">
<link  href="{{asset ('//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css')}}" rel="stylesheet" type="text/css">
<script type="text/javascript" src="{!! asset('js/bootstrap-colorpicker.min.js') !!}">
</script>
<script type="text/javascript" src="{!! asset('js/bootstrap-formhelpers.js') !!}">
</script>
<script type="text/javascript" src="{!! asset('js/template.js') !!}"></script>
<script type="text/javascript" src="{!! asset('js/bootstrap-filestyle.min.js') !!}">
</script>

</html>
@endsection @show

Can anyone help me get started?

2
  • I don't quite understand this <img src="{{ asset($website->html )}}"/>. Isn't $website->html full of html-code? Commented Jan 31, 2017 at 13:48
  • It is, I am working on it all the time trying to fix it, how would I just display that html code from database? Even better without much code in blade.php so it just displays html from the database? Commented Jan 31, 2017 at 13:54

1 Answer 1

1

You're wanting to Displaying Unescaped Data:

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

{!! $website->html !!}
Sign up to request clarification or add additional context in comments.

3 Comments

I still get this error Method App\Http\Controllers\BuilderController::websites() does not exist
That means that Laravel can't find your websites function in BuilderController. That's a completely different issue.
but question is why cannot laravel find it, it is there

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.