2

This is my AuthorController.php

<?php

namespace App\Http\Controllers;

use App\Models\Post;
use App\Models\Author;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Illuminate\Support\Facades\Redirect;
use View;
use Input;

class AuthorController extends Controller {

  public function index()
  {
    $author_name = Input::get('name');
    $author_slug = Input::get('slug');
    $author_bio = Input::get('bio');

    $new_author = Author::create(array('name' => $author_name, 'slug' => $author_slug, 'bio' => $author_bio));

    return Redirect::to('/');

  }

}

?>

This is what's in my Routes file

Route::post('/create-author', [
  'as' => 'create-author',
  'uses' => 'AuthorController@index'
]);

I'm not quite sure what's wrong, I tried hardcoding something into the database with $new_author = Author::create(array('name' => 'John)); and it worked, would it be the directory in which the Input class is in relative to my AuthorController.php, which is in App\Controllers

3
  • Try this, use Illuminate\Support\Facades\Input; Commented Feb 24, 2016 at 4:34
  • 1
    It worked, thank you! Can you write that in an answer so I can choose it as correct ? Thank you Commented Feb 24, 2016 at 4:35
  • 1
    Okay thanks i'll accept in approximately 9 minutes :) Commented Feb 24, 2016 at 4:37

2 Answers 2

1

Use this in your controller,

 use Illuminate\Support\Facades\Input; 
Sign up to request clarification or add additional context in comments.

Comments

0

Each time when you want to use predefined class , you can see the alias defined for it in config/app.php. you should use via facade only,

use Illuminate\Support\Facades\Input;

Comments

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.