【问题标题】:Don't show the URL's parameters in Laravel 4.1在 Laravel 4.1 中不显示 URL 的参数
【发布时间】:2014-10-17 06:40:39
【问题描述】:

我在 Laravel 4.1 中有一个针对用户的 CRUD 当用户想看他的数据时,url是:mydomain.com/public/users/3(show方法)。

如何在 url 中隐藏 id “3”?那么,如果数字是可见的,用户就可以看到其他用户的数据(如 4,5 或其他 id)?

谢谢

在我的 filter.php 中我有:

Route::group(array('before' => 'auth'), function()
{   
    Route::resource('users', 'UserController');
});

【问题讨论】:

  • 你可以定义一个过滤器,只有登录的用户可以调用这个路由
  • 我该怎么做?
  • 我认为这是我的问题的解决方案:stackoverflow.com/questions/15737491/…
  • 所以,删除这个问题然后;-)
  • 真的不需要删除问题,您也可以发布您的解决方案作为答案。

标签: laravel-4


【解决方案1】:

终于解决了。

在 UserController.php 中:

public function show()
{
    //
    $usuario = Auth::user();

    // show the view and pass the nerd to it
    return View::make('users.show')
        ->with('elusuario', $usuario);
}

在 show.blade.php 中

@extends ("layout/layout")

@section ("principal")

        <div class="form-group">
            {{ Form::label('nombre', 'Nombre') }}
            {{ Form::text('nombre',null, array('class' => 'form-control','placeholder'=>$elusuario->nombre,'disabled'=>'disabled')) }}
        </div>

        <div class="form-group">
            {{ Form::label('email', 'Email') }}
            {{ Form::email('email',null, array('class' => 'form-control','placeholder'=>$elusuario->email,'disabled'=>'disabled')) }}
        </div>


        <a class="btn btn-success" href="{{ URL::to('users/' . $elusuario->id . '/edit') }}">Modificar datos</a>

@stop

这解决了问题,并且 url 不显示用户的 id。简单地称为 mydomain.com/public/users/perfil 并具有来自会话变量的数据(id、名称等)。

【讨论】:

    猜你喜欢
    • 2014-12-17
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 2019-09-05
    相关资源
    最近更新 更多