3

I'm trying to send an email filled with a form from a Laravel app.

When you hit submit it throws the above error:

Fatal error: Class 'App\Http\Controllers\Input' not found

Not sure why as I don't have, nor knew I needed to have an Input controller, or what I would put in it.

Below is the content of the controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class contact extends Controller
{
     // This function will show the view
    public function showForm()
    {
        return view('pages.contact');
    }

     public function handleFormPost()
     {
         $input = Input::only('name', 'email', 'msg');

         $validator = Validator::make($input,
             array(
                 'name' => 'required',
                 'email' => 'required|email',
                 'msg' => 'required',
             )
         );

         if ($validator->fails())
         {
             return Redirect::to('contact')->with('errors', $validator->messages());
         } else { // the validation has not failed, it has passed


            // Send the email with the contactemail view, the user input
            Mail::send('contactemail', $input, function($message)
            {
                 $message->from('[email protected]', 'Your Name');

                 $message->to('[email protected]');
             });

             // Specify a route to go to after the message is sent to provide the user feedback
             return Redirect::to('thanks');
         }

     }
 }

Below is the view of the forum (based on bootstrap):

<div class="container">
    <h1>A basic contact form</h1>
    <form id="contact" method="post" class="form" role="form">

        @if(Session::has('errors'))
            <div class="alert alert-warning">
                @foreach(Session::get('errors')->all() as $error_message)
                    <p>{{ $error_message }}</p>
                @endforeach
            </div>
        @endif

        <div class="row">
            <div class="col-xs-6 col-md-6 form-group">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input class="form-control" id="name" name="name" placeholder="Name" type="text"autofocus="">
            </div>
            <div class="col-xs-6 col-md-6 form-group">
                <input class="form-control" id="email" name="email" placeholder="Email" type="text">
            </div>
        </div>
        <textarea class="form-control" id="message" name="msg" placeholder="Message" rows="5"></textarea>
        <br>
        <div class="row">
            <div class="col-xs-12 col-md-12 form-group">
                <button class="btn btn-primary pull-right" type="submit">Submit</button>
            </div>
        </div>
    </form>
</div>
1

4 Answers 4

9

Used this in your contact.php Controllers-

use Illuminate\Support\Facades\Input;

your error will get fixed. Thanks.

Sign up to request clarification or add additional context in comments.

Comments

3

Input:: is replaced with Request::. Instead of

$input = Input::only('name', 'email', 'msg');

use this:

$input = Request::only('name', 'email', 'msg');

And if you get error something about 'should not use statically' just add this at the top of your file

use Request;

If you already have this line:

use Illuminate\Http\Request;

delete it because you can't have two classes with the same name in one file

Comments

2
public function handleFormPost(Request $request)
{
    $name = $request->get('name');
    $email = $request->get('email');
    $msg = $request->get('msg');   
}

OR

public function handleFormPost(Request $request)
{
    $input = $request->all();   
}

Comments

0

you not use input try this :

use Input;

Put it after the namespace declaration like this

<?php 

namespace App\Http\Controllers; 
use Input;
...

?>

3 Comments

where would I put that?
<?php namespace App\Http\Controllers; use Input;
Error Class 'Input' not found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.