2016-09-21 77 views
1

我与laravael 5.3.9一起工作。 在我控制我用为什么在Illuminate support facade input中找不到方法帖子

Illuminate\Support\Facades\Input;

但是,当我尝试使用方法后那样的用户表单获取输入:

function add(){ 
    $fullName = Input::post('fullName' , 'test'); 

我得到这个错误。

the only method that Input class has is "get" .

我不希望在我的系统我想方法postdeleteput ....

+0

你在''route.php''文件中定义了什么?你有没有在那里定义路线?在你添加函数的时候,你错过了结束括号或者它的简单类型错误!把你的代码放在这里以更好地了解你的错误。 – Tarunn

+0

相关命令routes/web.php文件是: Route :: match(['get','post'],'area_owners/add','area_owners @ add'); 控制器中的相关代码是: function add(){fullName = Input :: post('fullName'); } –

+0

在您的控制器中尝试下面的代码,并让我知道。 ''Input :: post''没有被使用,而是使用'Request facade''。 – Tarunn

回答

0

我想,Input::post方法不与L5.3用来工作。使用Request facade或$request来获取您的输入变量。

试试这个在您的控制器

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

class area_owners extends Controller 
{ 
    function add(Request $request) 
    { 
     // I assume all these input variable have same name in you FORM. 
     $fullName = $request->input('fullName'); 
     $smsCode = $request->input('smsCode'); 
     $authorizationId = $request->input('authorizationId'); 
     $areaNumber‌​ = $request->input('areaNumber‌​'); 
     $neigh_project_Id = $request->input('neigh_project_Id'); 

     $area_owners = DB::table('area_owners') 
      ->insert(['fullName'=>$fullName, 
        'smsCode'=>$smsCode, 
        'authorizationId'=>$authorizationId, 
        'are‌​aNumer'=>$areaNumber‌​, 
        'neigh_project_Id'=‌​>$neigh_project_Id])‌​; 
    return view('area_owners_add', ['area_owners' => $area_owners]); 
    } 
} 

让我知道,如果它帮助。

+0

是的,它工作的部分...表单被提交,行被添加到表中,但它完全像GET方法,因为所有参数都显示在url中: http:// localhost:8000/area_owners/add?fullName =% D7%93%D7%95%D7%93%D7%99 +%D7%A1%D7%9C%D7%A2&电话= 05485887732&电子邮件= danielgontar%40gmail.com&可供出售= 1&dateIn = 2016年8月16日&smsCode = 1&authorizationId = 1&areaNumber = 1&neigh_project_Id = 1 ,我不想那 –

+0

你发布你的“表单”的方法。在你的''View file''中,检查表单标签。 ''

...'' – Tarunn

+0

对不起,我认为你是对的...我忘了在我的表单中填写方法以从发布中获取...修复问题并更新u。我认为你给出了正确的解决方案。 –

相关问题