我是Laravel的新手,在存储和更新Model时遇到了问题。
这是我的存储方法
public function store(Request $request)
{
$input = Request::all();
Klijent::create($input);
return redirect('klijenti');
}
我必须包含use Request;
才能使其工作。
这是我的更新方法
public function update(Request $request, $id)
{
//
$klijent = Klijent::find($id);
$klijent->update($request->all());
return redirect('klijenti/'. $id);
}
我必须包含use Illuminate'Http'Request;
才能使其工作。
但如果我不使用第一个,我会在使用存储方法时出现这个错误:
Non-static method Illuminate'Http'Request::all() should not be called statically, assuming $this from incompatible context
如果我不使用第二个,当我使用更新方法时会出现以下错误:
Call to undefined method Illuminate'Support'Facades'Request::all()
如果我同时使用它们,我会得到这个错误:
Cannot use Illuminate'Http'Request as Request because the name is already in use
您需要调用等非静态方法
$input = $request->all();
在您的第一个函数中。第二个错误是因为Illuminate'Support'Facades'Request
没有可调用的all
方法。第三个错误是名称空间冲突,因为在PHP中不能有两个同名的类。