我是laravel初学者,并试图将id传递给控制器方法show。它在页面重新加载后不显示任何内容。我尝试了一些谷歌的东西。它没有提供任何帮助。下面我相关的代码给出:
admin.blade.php
<div class="showOne">
<?php if(isset($users)){
var_dump($users);
}
?>
@foreach($inputs as $key => $user)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->address }}</td>
<td>{{ $user->phone }}</td>
<td>
{{ Form::open(['route' => ['admin.show', $user->id], 'method' => 'get']) }}
{{ Form::button('Details') }}
{{ Form::close() }}
</td>
<td>
{{ Form::open(['route' => ['admin.edit', $user->id], 'method' => 'get']) }}
{{ Form::button('Edit') }}
{{ Form::close() }}
</td>
<td>
{{ Form::open(['route' => ['admin.delete', $user->id], 'method' => 'get']) }}
{{ Form::button('Delete') }}
{{ Form::close() }}
</td>
</tr>
@endforeach
控制器:
class AdminController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
// get all the inputs
$inputs = Userdatas::all();
// load the view and pass the inputs
return View::make('pages.admin')
->with('inputs', $inputs);
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$user = Userdatas::find($id);
var_dump($user);
die();
return View::make('pages.admin')
->with('users', $user);
}
}
路线:
Route::get('admin', [
'uses' => '[email protected]'
]);
Route::get('admin/{id}', [
'uses' => '[email protected]',
'as' => 'admin.show'
]);
当您单击该按钮,请问网址是什么样子? 'admin/1'? – lukasgeiter 2015-02-06 08:37:00
不,但我检查了按钮,它看起来像admin/1 – WahidSherief 2015-02-06 08:40:25
那么你点击它后的URL是什么? – lukasgeiter 2015-02-06 08:44:11