【发布时间】:2014-08-29 17:58:01
【问题描述】:
我正在使用Laravel 4来构建应用程序。
这是我的代码:
public function handleCreateCandle(){
$candle = new Candle;
$candle->name = Input::get('name');
$candle->body = Input::get('body');
$candle->user_id = Sentry::getUser()->id;
$candle->save();
return Redirect::action('User_BaseController@getPrayerSpace')->with('message', 'Thank you for lighting candle');
}
问题不是返回消息,而是我想将 json 数组返回到视图,其中包含成功代码以及 $candle 的名称和正文。谁能建议我如何做到这一点?
【问题讨论】:
-
你是什么意思?你想要一个 json 字符串而不是纯文本吗?然后只使用json_encode? ->with('message', json_encode($candle))
标签: php mysql laravel laravel-4