2016-12-05 88 views
-1

我想问一下如何删除路由名中的项目名。我通过教程去,并按照每个练习时,我曾经试图发布是这样进行登记:如何在Laravel中删除路径名中的项目名称

<form action = "/user/register" method = "post"> 
    <input type = "hidden" name = "_token" value = "<?php echo csrf_token() ?>"> 

    <table> 
     <tr> 
      <td>Name</td> 
      <td><input type = "text" name = "name" /></td> 
     </tr> 

     <tr> 
      <td>Username</td> 
      <td><input type = "text" name = "username" /></td> 
     </tr> 

     <tr> 
      <td>Password</td> 
      <td><input type = "text" name = "password" /></td> 
     </tr> 

     <tr> 
      <td colspan = "2" align = "center"> 
       <input type = "submit" value = "Register" /> 
      </td> 
     </tr> 
    </table> 

    </form> 

,但是当我张贴,它显示一个错误说URL中没有发现,所以我说的项目名称在url:/test_laravel/user/register是新的操作。那么它的工作,但如何摆脱这一点?

谢谢!

+0

<形式方法= “POST” 行动= “{{动作( 'Yourcontroller @功能')}}” 接收字符集=“UTF -8“> –

+0

谢谢@Shanukk,但它会抛出一个错误。这是新的动作:''{{action('UserRegistrationController @ postRegister')}}''。 –

+0

Route :: post('/',array('as'=>'postRegister','uses'=>'UserRegistrationController @ postRegister'));在路线 –

回答

0

这就是设计路线的原因。

制作一个路径文件;

Route::post('user/registration',['uses' => '[email protected]','as' => 'giveRouteAUniqueName']); 

uses accepts controller name and after @ accepts method(function) of the controller 
and as gives you ability to assign new unique name to route now you can call 
route('RouteName'); in our case its route('giveRouteAUniqueName') 
1

为了让你可以使用适当的URL:

route()

url函数产生一个完全合格的URL给定的路径:

$url = route('routeName'); 
$url = route('routeName', ['id' => 1]); 

url()

的网址函数生成完整$ URL =路线( 'routeName',[ 'ID'=> 1]); Y限定的URL为给定的路径

echo url('user/profile'); 
echo url('user/profile', [1]); 

action()

action函数为给定的控制器操作生成一个URL。您不需要将完整的名称空间传递给控制器​​。取而代之的是,相对的控制器类名到App\Http\Controllers命名空间传递:

$url = action('[email protected]'); 
$url = action('[email protected]', ['id' => 1]); 
+0

非常感谢你!它现在有效。 –

相关问题