2

here's my form code :

 <div class="form-group">
          <label>Warranty:</label>
          {{ Form::checkbox('warranty', 0, false) }}
 </div>

here's my controller code :

public function save(Request $request, $obj = null) {

if (!$obj) {
    $obj = new Service;
}
(Input::has('warranty')) ? true : false;
return $this->saveHandler($request, $obj);
}

it throws this error Class 'App\Http\Controllers\Input' not found

any idea ?

4 Answers 4

5

You can use request object to get the warranty input as:

$request->get('warranty')

or

$request->has('warranty')
Sign up to request clarification or add additional context in comments.

1 Comment

it throws syntax error, unexpected 'return' (T_RETURN).
3
 $request->merge(array('checkbox_name' => $request->has('checkbox_name') ? true : false));
Object::create($request->all());

This is how I save boolean parameters which are checkboxes in form.

Or simply give your checkbox value

 {{ Form::checkbox('checkbox_name', 1) }}

Comments

1

Add this at top in the controller,

use Illuminate\Support\Facades\Input;

3 Comments

it throws Class 'Input' not found.
Do you have Input Class in controllers?
'App\Http\Controllers\Input ' says you have Input class in controllers which cannot be found. If you want to use Input Facade you have to remove 'App\Http\Controllers\Input ' and replace it with Illuminate\Support\Facades\Input;
1

Input facade was removed in latest verison, so you can add it to config/app.php:

'Input' => Illuminate\Support\Facades\Input::class,

Or add this line to the beginning of a controller:

use Illuminate\Support\Facades\Input;

Or write full path when you use it:

(\Illuminate\Support\Facades\Input::has('warranty')) ? true : false;

3 Comments

it throws Class 'Input' not found
As far as I know, it was removed time ago: "The Input facade, which was primarily a duplicate of the Request facade, has been removed. If you are using the Input::get method, you should now call the Request::input method. All other calls to the Input facade may simply be updated to use the Request facade." From 6.x documentation: laravel.com/docs/6.x/upgrade#the-input-facade
Forgot in previous comment: You need to use $request->input('input_name') instead of Input Facade.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.