laravel lumen Входной класс не найден

Привет, я тестирую люмен-новое микро-фреймворк laravel, и когда я пытаюсь получить информацию от веб-службы, я получаю эту ошибку

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

вот мой код:

<?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();
}
}
}

5

Решение

Раскоментируйте $app->withFacades(); в bootstrap/app.php чтобы позволить вам использовать фасад в вашем контроллере.

<?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();
}
}
}

Использовать внедрение зависимостей для внедрения Illuminate\Http\Request класс в ваши методы.

<?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();
}
}
}
7

Другие решения

   <?php namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request as Request;

class WsController extends Controller {

public function addUser()
{
//creating a new user object from User model class
$user = new Models\User;
//getting the email value from the email input like Input::get('email');
$user->email = Request::input('email');
//same as above happen with the rest of the lines
$user->password = strtoupper(md5(Request::input('password')));
$user->first_name = Request::input('first_name');
$user->last_name = Request::input('last_name');
//User model has a save() method, so is calling if return true the if block will be executed
if($user->save()){
return Models\User::all();
}
}

//this is the best way in lumen to execute some method, because lumen is powerful in small APIs and restful services
}
-1

По вопросам рекламы [email protected]