Hey i wan't to echo something with belongsTo but the output gives me some strange characters back.
class Leviews extends Entity
{
public $table = 'reviews';
public function ravatar()
{
return $this->belongsTo('User', 'author', 'username')->select('avatar');
}
now when i echo the data with {{ $item->ravatar }} im getting this
{"avatar":"avatars\/1.jpg"}
and it should be
avatars/1.jpg
what im doing wrong?
edit here is the Controller
<?php
use Carbon\Carbon;
use Lib\Reviews\LeviewsRepository;
use Lib\Services\Scraping\Scraper;
use Lib\Services\Validation\LeviewsValidator;
class LeviewsController extends \BaseController {
/**
* Leviews repository instance.
*
* @var Lib\Leviews\LeviewsRepository
*/
protected $repo;
/**
* validator instance.
*
* @var Lib\Services\Validation\LeviewsCreateValidator
*/
private $validator;
/**
* Leviews scraper isntance.
*
* @var Lib\Services\Scraping\NewScraper;
*/
private $scraper;
public function __construct(LeviewsRepository $lreviews, LeviewsValidator $validator, Scraper $scraper)
{
$this->beforeFilter('csrf', array('on' => 'post'));
$this->beforeFilter('logged', array('except' => array('index', 'show', 'paginate')));
$this->beforeFilter('news:create', array('only' => array('create', 'store')));
$this->beforeFilter('news:edit', array('only' => array('edit', 'update')));
$this->beforeFilter('news:delete', array('only' => 'destroy'));
$this->beforeFilter('news:update', array('only' => 'updateFromExternal'));
$this->repo = $lreviews;
$this->scraper = $scraper;
$this->validator = $validator;
}
/**
* Display list of paginated news.
*
* @return View
*/
public function index()
{
return View::make('Leviews.Index');
}
/**
* Display form for creating new news items.
*
* @return View
*/
public function create()
{
return View::make('Leviews.Create');
}
/**
* Store a newly created news item.
*
* @return Redirect
*/
public function store()
{
$input = Input::except('_token');
if ( ! $this->validator->with($input)->passes())
{
return Redirect::back()->withErrors($this->validator->errors())->withInput($input);
}
//escape double qoutes
$input['title'] = htmlspecialchars($input['title']);
$this->repo->store($input);
return Redirect::back()->withSuccess( trans('main.news create success') );
}
/**
* Display single news items.
*
* @param int $id
* @return View
*/
public function show($id)
{
$lreviews = $this->repo->byId($id);
if ($lreviews->full_url && ! $lreviews->fully_scraped)
{
$lreviews = $this->repo->getFullLeviewsItem($lreviews);
}
return View::make('Leviews.Show')->with(compact('news'))->withRecent($this->repo->latest());
}
/**
* Displays form for editing news item.
*
* @param int $id
* @return View
*/
public function edit($id)
{
$lreviews = $this->repo->byId($id);
return View::make('Leviews.Edit')->withLeviews($lreviews);
}
/**
* Updates the news item.
*
* @param int $id
* @return Redirect
*/
public function update($id)
{
$input = Input::except('_token', '_method');
$lreviews = $this->repo->byId($id);
if ($lreviews->title === $input['title'])
{
//dont check for title uniqueness when updating if
//title was not updated.
$this->validator->rules['title'] = 'required|min:2|max:255';
}
if ( ! $this->validator->with($input)->passes())
{
return Redirect::back()->withErrors($this->validator->errors())->withInput($input);
}
//escape double qoutes
$input['title'] = htmlspecialchars($input['title']);
$this->repo->update($lreviews, $input);
return Redirect::back()->withSuccess( trans('main.news update success') );
}
/**
* Delete specified news item.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$this->repo->delete($id);
return Response::json(trans('main.news delete success'), 200);
}
/**
* Updates news from external sources.
*
* @return void
*/
public function updateFromExternal()
{
$this->scraper->updateLeviews();
Event::fire('Leviews.Updated', Carbon::now());
return Redirect::back()->withSuccess( trans('dash.updated news successfully') );
}
}
and here the view
@if ($options->enableNews())
@foreach($lreviews as $k => $item)
{{ $item->body }}
{{ $item->ravatar }}
@endforeach
@endif
{{ $item->body }} is without strange characters
Aucun commentaire:
Enregistrer un commentaire