gpt4 book ai didi

php - 第 5 行 : Call to undefined function link_to_route()

转载 作者:行者123 更新时间:2023-11-29 06:07:52 31 4
gpt4 key购买 nike

好吧,我一直在使用 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');

我的 usercontroller.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',
];
}

最佳答案

要使用 link_to_route 助手,您需要拉取 "illuminate/html": "~5.0"包。此处提供说明:http://laravel.com/docs/5.0/upgrade#upgrade-5.0请参阅表单和 Html 助手部分。

更新:如果您不需要 Html 帮助器,您可以使用以下方法:

// For any routes
<a href="{{ url('users/create') }}">Add new user</a>

// For named routes
<a href="{{ route('users.create') }}">Add new user</a>

关于php - 第 5 行 : Call to undefined function link_to_route(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40217215/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com