Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel, return view with Request::old

fHello, for example, i have simple input field (page index.php)

<input type="text" name="name" value="{{Request::old('name')}}">

In controller

$this->validate($request, ['name' => 'required']);

After this, i want make some check without Laravels rules. For example

if($request['name'] != 'Adam') { return view('index.php'); } 

But after redirect, Request::old is empty. How to redirect to index.php and save old inputs and use Request::old, or its impossible? Thank you.

PS its example, i know that Laravel has special rules for check inputs value

like image 568
Vladislav Avatar asked May 15 '16 18:05

Vladislav


People also ask

How do I return a view in laravel?

Views may also be returned using the View facade: use Illuminate\Support\Facades\View; return View::make('greeting', ['name' => 'James']); As you can see, the first argument passed to the view helper corresponds to the name of the view file in the resources/views directory.

What is request -> input () in laravel?

input() is a method of the Laravel Request class that is extending Symfony Request class, and it supports dot notation to access nested data (like $name = $request->input('products.0.name') ).

How do I load a view in laravel?

Loading a view in the controller is easy. You just need to add `view('viewname')` method while returning from the controller method. `view()` is a global helper in Laravel. In this method, you just need to pass the name of the view.

How do I get params in laravel?

Laravel routes are located in the app/Http/routes. For instance, to pass in a name parameter to a route, it would look like this. Route::get('/params/{name}', function ($name) { return $name }); By convention, the Controller function accepts parameters based on the parameters provided.


2 Answers

Old question, but for future reference, you can return the input to a view by flashing the request input just beforehand.

i.e.

session()->flashInput($request->input());

return view('index.php');

then in your view you can use the helper

{{ old('name') }}

or

{{Request::old('name')}}
like image 147
Paul Wright Avatar answered Oct 13 '22 09:10

Paul Wright


You can use back() instead if any url. These function helps you in any case to be able to return to previous page without writing route.

return back()->withInput();
like image 45
Javid Aliyev Avatar answered Oct 13 '22 10:10

Javid Aliyev