【发布时间】:2017-03-06 03:50:04
【问题描述】:
好的,所以我一直在使用 Laravel 设置我的第一个网站,但我一直遇到这个错误。我目前正在尝试设置索引页面(它是针对 CRUD 应用程序的),但此错误不断弹出。
FatalErrorException in 06f534e736fde409cb38fab481f04cd04f7fbca4.php line 5:
Call to undefined function link_to_route()
我的 web.php(路线):
<?php
Route::get('/', function () {
return view('index');
});
Route::resource('users', 'UserController');
Route::get('/register', 'UserController@showUserRegistration');
Route::post('/register', 'UserController@saveUser');
我的用户控制器.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class UserController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$users = User::all();
return View::make('users.index', compact('users'));
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return View::make('users.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}
我的 index.blade.php:
@section('main')
<h1>All Users</h1>
<p>{{ link_to_route('users.create', 'Add new user') }}</p>
@if ($users->count())
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Phone</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td>{{ $user->username }}</td>
<td>{{ $user->password }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->phone }}</td>
<td>{{ $user->name }}</td>
<td>{{ link_to_route('users.edit', 'Edit', array($user->id), array('class' => 'btn btn-info')) }}</td>
<td>
{{ Form::open(array('method'
=> 'DELETE', 'route' => array('users.destroy', $user->id))) }}
{{ Form::submit('Delete', array('class' => 'btn btn-danger')) }}
{{ Form::close() }}
</td>
</tr>
@endforeach
</tbody>
</table>
@else
There are no users
@endif
@stop
还有我的 user.blade.php(布局):
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
【问题讨论】:
标签: php html mysql sql laravel