访问控制器在视图层

时间:2017-10-12 09:16:57

标签: php laravel-5

我从控制器返回了一个值。当我在视图刀片中使用该值时,它会显示语法错误 这是我的代码,

控制器

public function edit($id)
{
        $a = DB::select('select * from users where id = "$pid"', array(1));
         return view('sample', ['users' => $a]);
}

在View blade中,

 {!! Form::Id('Id', $value = {{$a}}, ['class' => 'form-control1', 'placeholder' => 'Id']) !!}

我如何更改代码,帮助我

1 个答案:

答案 0 :(得分:1)

You can do it wit eloquent like this :

public function edit($id)
{
        $a = User::find($id);
         return view('sample', ['user' => $a]);
}

And on top of your controller add the import :

use App\User;

In the view it's user that will be seen not a so :

<input type="text" name="id" value="{{ $user->id }}" />
{!! Form::email('email', $user->email, ['class' => 'form-control1', 'placeholder' => 'email']) !!}