我有这个视图页面index.blade.php
@section('main')
<h1>All Users</h1>
<p><a href={!! url('users\create') !!}>Add new user</a></p>
@if ($users->count())
<table border="2">
<tr><td>s.n.</td><td>name</td><td>email</td><td>options</td>
@foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td><a href={{ url('users\{id}\edit', $user->id)}}>Edit</a>
<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
</table>
@else
There are no users
@endif
@stop
和控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
class usercontroller extends Controller
{
public function index()
{
$users=User::all();
return view('users.index', compact('users'));
}
public function create()
{
return View('users.create');
}
public function store()
{
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if ($validation->passes())
{
User::create($input);
return Redirect::route('users.index');
}
return Redirect::route('users.create')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors.');
}
public function show($id)
{
//
}
public function edit($id)
{
$user = User::find($id);
if (is_null($user))
{
return Redirect::route('users.index');
}
return View('users.edit', compact('user'));
}
public function update($id)
{
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if ($validation->passes())
{
$user = User::find($id);
$user->update($input);
return Redirect::route('users.show', $id);
}
return Redirect::route('users.edit', $id)
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors.');
}
public function destroy($id)
{
User::find($id)->delete();
return Redirect::route('users.index');
}
}
和
routes.php
Route::resource('users', 'UserController');
但是当我进入laravel / public / users时,它会显示白色空白页面。与任何其他路线相同的问题,例如:
Route::get('/users/edit/{id}','UserController@edit');
Route::put('/users/{id}','UserController@update');
Route::delete('/users/{id}','UserController@delete');
当我按照https://laravelcollective.com/docs/5.2/html这些步骤使用表单时出现问题。 。之前的错误是找不到“类形式”。
app / User.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class User extends BaseModel
{
protected $primarykey='id';
protected $table='users';
protected $fillable=array('name','email','password');
public static $rules = array(
'name' => 'required|min:5',
'email' => 'required|email'
);
}
和basemodel
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class BaseModel extends Model {
public function selectQuery($sql_stmt) {
return DB::select($sql_stmt);
}
public function sqlStatement($sql_stmt) {
DB::statement($sql_stmt);
}
}
答案 0 :(得分:0)
首先将您的控制器文件名 app / Http / Controller / usercontroller.php 更改为 app / Http / Controller / UserController.php 。
然后UserController.php你编辑你的类名如下:
terminal
Started GET "/clients/myzenica?phone=%229650661678%22" for 127.0.0.1 at 2016-03-15 11:21:23 +0530
Processing by ClientsController#myzenica as */*
Parameters: {"phone"=>"\"9650661678\"", "client"=>{}}
Client Load (0.3ms) SELECT `clients`.* FROM `clients` WHERE `clients`.`phone` = '\"9650661678\"'
Completed 200 OK in 2ms (Views: 0.7ms | ActiveRecord: 1.2ms)
然后确保您的型号名称 app / User.php 包含所有表格字段和表格。
在 app / Http / routes.php 你设置另一条路线
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
class UserController extends Controller
然后你可以输入laravel / public / users