usertest
usertest

Reputation: 409

Access controller return value in view laravel

I've returned a value from my controller.When I use the value in my view blade,it shows Syntax error Here is my code,

Controller

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

And in View blade,

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

How 'ld I change my code,Help me

Upvotes: 2

Views: 2423

Answers (1)

Maraboc
Maraboc

Reputation: 11083

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']) !!}

Upvotes: 1

Related Questions