Php 无法在控制器的刀片模板中显示变量
我不知道如何在laravel的刀片模板中显示路由名称。请在下面找到示例代码。多谢各位 从控制器(StaffsController.php) 刀片:Php 无法在控制器的刀片模板中显示变量,php,laravel,laravel-blade,Php,Laravel,Laravel Blade,我不知道如何在laravel的刀片模板中显示路由名称。请在下面找到示例代码。多谢各位 从控制器(StaffsController.php) 刀片: {{ $thisRoute }} (1/1) UnexpectedValueException The Response content must be a string or object implementing __toString(), "boolean" given. public function index() { $thi
{{ $thisRoute }}
(1/1) UnexpectedValueException
The Response content must be a string or object implementing __toString(), "boolean" given.
public function index()
{
$thisRoute = Route::current()->uri();
return dd($thisRoute);
}
这是变量转储
/home/vagrant/Code/spark/app/Http/Controllers/StaffsController.php:20:string 'staffs' (length=6)
错误:
{{ $thisRoute }}
(1/1) UnexpectedValueException
The Response content must be a string or object implementing __toString(), "boolean" given.
public function index()
{
$thisRoute = Route::current()->uri();
return dd($thisRoute);
}
当我将控制器中的代码更改为:
{{ $thisRoute }}
(1/1) UnexpectedValueException
The Response content must be a string or object implementing __toString(), "boolean" given.
public function index()
{
$thisRoute = Route::current()->uri();
return dd($thisRoute);
}
我将“staff”作为输出,这是正确的,它是来自转储的字符串,对吗?将您的return语句更改为如下所示:
return view('staff.list', compact('thisRoute'));
如果您使用的是laravel 5.3或更高版本,则可以获得如下路由名称:
Route::currentRouteName();
这样,您就不必将其从控制器传递到视图,只需直接从刀片视图使用即可:
{{ Route::currentRouteName() }}
对不起,伙计们,我解决了这个问题。我错过了队列中的
-
returnview('staff.list')>with(compact('thisRoute'))代码>
改成
return view('staff.list')->with(compact('thisRoute'));
我犯了一个错误
谢谢您希望打印什么?为什么在dd
中使用Route::current()->uri()
但在第一个示例中仅使用Route::current()代码>?还有@u_mulder,对不起,这是一个打字错误。我更正了代码。@Laerte我想在BladeStore mate中将staff作为字符串输出,将代码更改为$thisRoute=Route::currentRouteName();返回视图('staff.list')>with(compact('thisRoute'))代码>但仍然有相同的错误请更改您的返回语句如下:返回视图('staff.list',compact('thisRoute');您还可以使用简短的语法:returnview('staff.list',compact('thisRoute')代码>