Laravel-Bootstrap Starter Управление контентом сайта

В настоящее время я работаю со стартовым сайтом здесь:
https://github.com/andrewelkins/Laravel-4-Bootstrap-Starter-Site

Любой HTML, который я добавляю в блог, преобразуется в текст. Например, тег hi tag (должен иметь квадратные скобки вокруг тега) преобразуется в hi внутри div. Я хочу, чтобы он просто выводил привет в теге как div
Вот контроллер

<?php

class AdminBlogsController extends AdminController {/**
* Post Model
* @var Post
*/
protected $post;

/**
* Inject the models.
* @param Post $post
*/
public function __construct(Post $post)
{
parent::__construct();
$this->post = $post;
}

/**
* Show a list of all the blog posts.
*
* @return View
*/
public function getIndex()
{
// Title
$title = Lang::get('admin/blogs/title.blog_management');

// Grab all the blog posts
$posts = $this->post;

// Show the page
return View::make('admin/blogs/index', compact('posts', 'title'));
}

/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function getCreate()
{
// Title
$title = Lang::get('admin/blogs/title.create_a_new_blog');

// Show the page
return View::make('admin/blogs/create_edit', compact('title'));
}

/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
// Declare the rules for the form validation
$rules = array(
'title'   => 'required|min:3',
'content' => 'required|min:3'
);

// Validate the inputs
$validator = Validator::make(Input::all(), $rules);

// Check if the form validates with success
if ($validator->passes())
{
// Create a new blog post
$user = Auth::user();

// Update the blog post data
$this->post->title            = Input::get('title');
$this->post->slug             = Str::slug(Input::get('title'));
$this->post->content          = Input::get('content');
$this->post->meta_title       = Input::get('meta-title');
$this->post->meta_description = Input::get('meta-description');
$this->post->meta_keywords    = Input::get('meta-keywords');
$this->post->user_id          = $user->id;

// Was the blog post created?
if($this->post->save())
{
// Redirect to the new blog post page
return Redirect::to('admin/blogs/' . $this->post->id . '/edit')->with('success', Lang::get('admin/blogs/messages.create.success'));
}

// Redirect to the blog post create page
return Redirect::to('admin/blogs/create')->with('error', Lang::get('admin/blogs/messages.create.error'));
}

// Form validation failed
return Redirect::to('admin/blogs/create')->withInput()->withErrors($validator);
}

/**
* Display the specified resource.
*
* @param $post
* @return Response
*/
public function getShow($post)
{
// redirect to the frontend
}

/**
* Show the form for editing the specified resource.
*
* @param $post
* @return Response
*/
public function getEdit($post)
{
// Title
$title = Lang::get('admin/blogs/title.blog_update');

// Show the page
return View::make('admin/blogs/create_edit', compact('post', 'title'));
}

/**
* Update the specified resource in storage.
*
* @param $post
* @return Response
*/
public function postEdit($post)
{

// Declare the rules for the form validation
$rules = array(
'title'   => 'required|min:3',
'content' => 'required|min:3'
);

// Validate the inputs
$validator = Validator::make(Input::all(), $rules);

// Check if the form validates with success
if ($validator->passes())
{
// Update the blog post data
$post->title            = Input::get('title');
$post->slug             = Str::slug(Input::get('title'));
$post->content          = Input::get('content');
$post->meta_title       = Input::get('meta-title');
$post->meta_description = Input::get('meta-description');
$post->meta_keywords    = Input::get('meta-keywords');

// Was the blog post updated?
if($post->save())
{
// Redirect to the new blog post page
return Redirect::to('admin/blogs/' . $post->id . '/edit')->with('success', Lang::get('admin/blogs/messages.update.success'));
}

// Redirect to the blogs post management page
return Redirect::to('admin/blogs/' . $post->id . '/edit')->with('error', Lang::get('admin/blogs/messages.update.error'));
}

// Form validation failed
return Redirect::to('admin/blogs/' . $post->id . '/edit')->withInput()->withErrors($validator);
}/**
* Remove the specified resource from storage.
*
* @param $post
* @return Response
*/
public function getDelete($post)
{
// Title
$title = Lang::get('admin/blogs/title.blog_delete');

// Show the page
return View::make('admin/blogs/delete', compact('post', 'title'));
}

/**
* Remove the specified resource from storage.
*
* @param $post
* @return Response
*/
public function postDelete($post)
{
// Declare the rules for the form validation
$rules = array(
'id' => 'required|integer'
);

// Validate the inputs
$validator = Validator::make(Input::all(), $rules);

// Check if the form validates with success
if ($validator->passes())
{
$id = $post->id;
$post->delete();

// Was the blog post deleted?
$post = Post::find($id);
if(empty($post))
{
// Redirect to the blog posts management page
return Redirect::to('admin/blogs')->with('success', Lang::get('admin/blogs/messages.delete.success'));
}
}
// There was a problem deleting the blog post
return Redirect::to('admin/blogs')->with('error', Lang::get('admin/blogs/messages.delete.error'));
}

/**
* Show a list of all the blog posts formatted for Datatables.
*
* @return Datatables JSON
*/
public function getData()
{
$posts = Post::select(array('posts.id', 'posts.title', 'posts.id as comments', 'posts.created_at'));

return Datatables::of($posts)

->edit_column('comments', '{{ DB::table(\'comments\')->where(\'post_id\', \'=\', $id)->count() }}')

->add_column('actions', '<a href="{{{ URL::to(\'admin/blogs/\' . $id . \'/edit\' ) }}}" class="btn btn-default btn-xs iframe" >{{{ Lang::get(\'button.edit\') }}}</a>
<a href="{{{ URL::to(\'admin/blogs/\' . $id . \'/delete\' ) }}}" class="btn btn-xs btn-danger iframe">{{{ Lang::get(\'button.delete\') }}}</a>
')

->remove_column('id')

->make();
}

}

Вот модель

<?php

используйте Освещение \ Поддержка \ Фасады \ URL;

Класс Post расширяет Eloquent {

/**
* Deletes a blog post and all
* the associated comments.
*
* @return bool
*/
public function delete()
{
// Delete the comments
$this->comments()->delete();

// Delete the blog post
return parent::delete();
}

/**
* Returns a formatted post content entry,
* this ensures that line breaks are returned.
*
* @return string
*/
public function content()
{
return nl2br($this->content);
}

/**
* Get the post's author.
*
* @return User
*/
public function author()
{
return $this->belongsTo('User', 'user_id');
}

/**
* Get the post's meta_description.
*
* @return string
*/
public function meta_description()
{
return $this->meta_description;
}

/**
* Get the post's meta_keywords.
*
* @return string
*/
public function meta_keywords()
{
return $this->meta_keywords;
}

/**
* Get the post's comments.
*
* @return array
*/
public function comments()
{
return $this->hasMany('Comment');
}

/**
* Get the date the post was created.
*
* @param \Carbon|null $date
* @return string
*/
public function date($date=null)
{
if(is_null($date)) {
$date = $this->created_at;
}

return String::date($date);
}

/**
* Get the URL to the post.
*
* @return string
*/
public function url()
{
return Url::to($this->slug);
}

/**
* Returns the date of the blog post creation,
* on a good and more readable format :)
*
* @return string
*/
public function created_at()
{
return $this->date($this->created_at);
}

/**
* Returns the date of the blog post last update,
* on a good and more readable format :)
*
* @return string
*/
public function updated_at()
{
return $this->date($this->updated_at);
}

}

Спасибо заранее за вашу помощь!

0

Решение

Это связано с тем, что вывод данных, которые вы используете, проходит через htmlentities через фигурные скобки лезвия. {{{ }}}, имея в виду;

<div>hi </div>

превращается в

<&lt;div&gt;hi &lt;/div&gt;

Чтобы предотвратить это и разрешить HTML в сообщениях, измените {{{ }}} в {{ }},

1

Другие решения

У вас есть два решения здесь:

  • Вы можете найти файл, в котором кодируется содержимое, и удалить код, выполняющий кодирование.
  • или когда вам нужно вывести значение, которое закодировано, просто декодируйте его, используя HTML::decode(), Таким образом, для зашифрованного содержимого сообщения вы можете написать в своем представлении HTML::decode($post->content),
1