Shift with red gradient lettering

Request injection

Premium
Laravel

Leverage the injected $request object in Controllers and Middleware instead of using Facades or helpers.

Before

public function store()
{
$widget = Widget::create([
'name' => request()->input('name'),
'user_id' => Auth::user()->id,
]);
 
Session::flash('message', 'Widget #' . $widget->id . ' created');
 
return redirect()->route('show', $widget);
}

After

public function store(Request $request)
{
$widget = Widget::create([
'name' => $request->input('name'),
'user_id' => $request->user()->id,
]);
 
$request->session()->flash('message', 'Widget #' . $widget->id . ' created');
 
return redirect()->route('show', $widget);
}

← Back to the Workbench Tasks

Sign in with any of the following services to connect Shift with your Laravel project.


Don't use one of these services?

Temporarily push your project to a free, private repository on one of these cloud-based services or upgrade your project locally with Shift for Docker.