我已将Facebook用户的朋友的FBID存储在mysql数据库的字符串中。字符串如下所示:
"fbid1,fbid2,fbid3...etc..."
我正在尝试在视图中使用特定的FBID(例如,调用配置文件图像)。我的问题是,我如何在Laravel 4视图中执行此操作?我正在尝试以下方法:
array = explode(",", {{ Auth::user()->friend_ids_unpacked}});
但是,这只是打印出其他部分为文本的字符串。我知道这是不正确的,但我不知道如何在Laravel的视图中执行php调用。
感谢您的帮助。
编辑:
错误日志:
Stack trace:
#0 /Applications/MAMP/htdocs/crowdsets/laravel-master/app/storage/views/2ed7fc8952dab08cf4cb4f4e3d40d1ab(119): Illuminate\Exception\Handler->handleError(8, 'Array to string...', '/Applications/M...', 119, Array)
#1 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(9032): include('/Applications/M...')
#2 /Applications/MAMP/htdocs/crowdsets/laravel-master/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(45): Illuminate\View\Engines\PhpEngine->evaluatePath('/Applications/M...', Array)
#3 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(8925): Illuminate\View\Engines\CompilerEngine->get('/Applications/M...', Array)
#4 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(8916): Illuminate\View\View->getContents()
#5 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(9510): Illuminate\View\View->render()
#6 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(9058): Illuminate\Http\Response->setContent(Object(Illuminate\View\View))
#7 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(4921): Symfony\Component\HttpFoundation\Response->__construct(Object(Illuminate\View\View))
#8 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(7811): Illuminate\Routing\Router->prepare(Object(Illuminate\View\View), Object(Illuminate\Http\Request))
#9 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(4762): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#10 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(481): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(470): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#12 /Applications/MAMP/htdocs/crowdsets/laravel-master/public/index.php(49): Illuminate\Foundation\Application->run()
#13 {main} [] []
答案 0 :(得分:5)
你正在尝试做两件不同的事情。假设你想要一群朋友 - 你这样做:
<? $array = explode(",", Auth::user()->friend_ids_unpacked); ?>
然后您可以像这样使用数组:
@foreach ($array as $x)
<p>This is another id: {{ $x }}</p>
@endforeach
答案 1 :(得分:0)
移动花括号以完全包含PHP调用:
{{ $array = explode(",", Auth::user()->friend_ids_unpacked); }}