我尝试使用表单请求保存数据,但不起作用。
数据返回错误数组或成功消息,但不保存数据。
我的代码出了什么问题:https://gist.github.com/kneipp/42f7d316b9bbc2157668
<?php
namespace App\Http\Requests;
use App\Http\Requests;
class ProfileFormRequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'intro' => 'required',
];
}
}
<?php
namespace App\Http\Controllers;
use App\Profile;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
class ProfileController extends Controller
{
public function update(Requests\ProfileFormRequest $request)
{
//$id = Auth::User()->id;
return \Redirect::route('profile.edit')->with('message', 'Dados salvos!');
}
}
答案 0 :(得分:1)
代码重构,感谢您使用Auth :: id()提示:
public function update(Requests\ProfileFormRequest $request)
{
Profile::find(Auth::id())
->fill($request->all())
->save();
return \Redirect::route('profile.edit')->with('message', 'Dados salvos!');
}