【发布时间】:2015-08-16 09:07:42
【问题描述】:
我有如下路线。
Route::get('profile/{username}', 'ProfileController@index');
ProfileController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class ProfileController extends Controller
{
function index() {
view('profile.index');
}
}
profile/index.blade.php
{username}
但是当我转到/profile/salep 时它没有回显用户名,这里缺少什么?
如果我将 ProfileController 更改为此(如下),它可以工作,但 PhpStorm 会为视图显示“无法访问的状态”。
class ProfileController extends Controller
{
function index($username) {
return $username;
view('profile.index');
}
}
我没有使用下面的结构(从文档中获取),因为我需要将我的变量传递给视图而不是返回,所以我想我需要返回并将它传递给视图。
Route::get('user/{id}', function ($id) {
return 'User '.$id;
});
【问题讨论】:
标签: php laravel-5.1