在 Laravel 中存储和更新 - 使用哪个请求?

use*_*193 2 php laravel

我是 Laravel 的新手,我在存储和更新模型时遇到了问题。

这是我的商店方法

 public function store(Request $request)
{

    $input = Request::all();

    Klijent::create($input);

    return redirect('klijenti');

}
Run Code Online (Sandbox Code Playgroud)

我必须包括在内use Request;才能使其发挥作用。

这是我的更新方法

    public function update(Request $request, $id)
{
    //

    $klijent = Klijent::find($id);

    $klijent->update($request->all());

    return redirect('klijenti/'. $id);

}
Run Code Online (Sandbox Code Playgroud)

我必须包括在内use Illuminate\Http\Request;才能使其发挥作用。

但是,如果我不使用第一个,则在使用 store 方法时会出现此错误:

Non-static method Illuminate\Http\Request::all() should not be called statically, assuming $this from incompatible context
Run Code Online (Sandbox Code Playgroud)

如果我不使用第二个,则在使用更新方法时会出现此错误:

Call to undefined method Illuminate\Support\Facades\Request::all()
Run Code Online (Sandbox Code Playgroud)

如果我同时使用它们,则会出现此错误:

Cannot use Illuminate\Http\Request as Request because the name is already in use
Run Code Online (Sandbox Code Playgroud)

wog*_*and 9

您需要调用非静态方法,例如

$input = $request->all();
Run Code Online (Sandbox Code Playgroud)

在你的第一个函数中。第二个错误是因为Illuminate\Support\Facades\Request没有all方法可以调用。第三个错误是命名空间冲突,因为在 PHP 中不能有两个同名的类。