Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel lumen Input class not found

Tags:

php

laravel

lumen

Hi im testing lumen new laravel micro-frameword and when i'm trying to get input from a web service im getting this error

Fatal error: Class 'App\Http\Controllers\Input' not found in   C:\wamp\www\lumen\app\Http\Controllers\WsController.php

here is my code :

<?php namespace App\Http\Controllers;

class WsController extends Controller {

 public function addUser()
  {
        $user = new Models\User;
        $user->email = Input::get('email');;
        $user->password = strtoupper(md5(Input::get('password')));
        $user->first_name = Input::get('first_name');
        $user->last_name = Input::get('last_name');
        if($user->save()){
            return Models\User::all();
        }
  }
 }
like image 562
karmous Avatar asked Apr 29 '15 11:04

karmous


1 Answers

Solution #1

Uncomment $app->withFacades(); in bootstrap/app.php to allow you to use the Facade in your controller.

<?php 

namespace App\Http\Controllers;

use Input;

class WsController extends Controller 
{

    public function addUser(Request $request)
    {
        $user = new Models\User;
        $user->email = Input::get('email');
        $user->password = strtoupper(md5(Input::get('password')));
        $user->first_name = Input::get('first_name');
        $user->last_name = Input::get('last_name');
        if($user->save()) {
            return Models\User::all();
        }
    }
}

Solution #2 (personal preference)

Use dependency injection to inject the Illuminate\Http\Request class into your methods.

<?php 

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class WsController extends Controller 
{

    public function addUser(Request $request)
    {
        $user = new Models\User;
        $user->email = $request->input('email');;
        $user->password = strtoupper(md5($request->input('password')));
        $user->first_name = $request->input('first_name');
        $user->last_name = $request->input('last_name');

        if($user->save()) {
            return Models\User::all();
        }
    }
}
like image 53
N.B. Avatar answered Nov 08 '22 06:11

N.B.