2015-04-29 25 views
5

Hi thử nghiệm im lumen laravel mới vi frameword và khi tôi đang cố gắng để có được thông tin từ một dịch vụ web im nhận được lỗi nàylaravel lớp lumen Input không tìm thấy

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

đây là mã của tôi:

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

Bạn có bỏ ghi chú 'withFacades' trong 'bootstrap.php'? –

+0

Bạn có thể thử nó ngay sau khi không gian tên của bạn, sử dụng App \ Http \ Controllers \ Input; –

Trả lời

7

giải pháp # 1

Bỏ ghi chú $app->withFacades(); trong bootstrap/app.php để cho phép bạn sử dụng cho mặt tiền trong điều khiển của bạn.

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

Giải pháp # 2 (sở thích cá nhân)

tiêm sử dụng phụ thuộc để tiêm lớp Illuminate\Http\Request vào phương pháp của bạn.

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

thx @ N.B. nó làm việc :) – karmous

+0

Làm thế nào để thêm '$ request' vào phương thức' GET'? – Volatil3

+1

@ Volatil3 - nó hoạt động tương tự cho tất cả các động từ HTTP. –

-1
<?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 
    } 
+0

Một chút giải thích cho những gì đã sai? – mins

Các vấn đề liên quan