سؤال

I'm working on Laravel framework so I just making different examples to learn.I wrote this code block:

show.blade.php

 <!doctype html>
    <html>
        <head>
            <meta charset="utf-8">
        </head>

        <body>
            <h1>Hello,{{ $user->username }}</h1>
        </body>
    </html>

route.php

Route::get('users/{username}',function($username){

    $user = User::whereUsername($username)->first();

    return View::make('users.show',['user=>$user']);
});

I m calling my users with this url :http://localhost:8888/l4/public/users/xxx

Error:

ErrorException
Undefined variable: user (View: /Applications/MAMP/htdocs/l4/app/views/users/show.blade.php)
هل كانت مفيدة؟

المحلول

Looks like you have a bug around. :)

Route::get('users/{username}',function($username){

    $user = User::whereUsername($username)->first();

    return View::make('users.show',['user' => $user]);
});

نصائح أخرى

Try:

return View::make('users.show')->with('user' , $user);

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top