Command line to create a controller
php artisan make:controller UserController
The controller into the solution after the other folders:
1. Create a CommonController.php, other documents are to succeed him
<?php namespace App\Http\Controllers\Admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class CommonController extends Controller { /* //图片上传 public function upload() { $file = Input::file('Filedata'); if($file -> isValid()){ $entension = $file -> getClientOriginalExtension(); //上传文件的后缀. $newName = date('YmdHis').mt_rand(100,999).'.'.$entension; $path = $file -> move(base_path().'/uploads',$newName); $filepath = 'uploads/'.$newName; return $filepath; } }*/ }
Calling file written as follows:
<?php namespace App\Http\Controllers\Admin; use App\Http\Model\Login\Admin; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Redis; require_once 'org/code/Code.class.php'; class AdminLoginController extends CommonController { public function login()
2. directly modify the namespace and references
? < PHP namespace App \ Http \ the Controllers \ BettingServer; // namespace of the current file BettingServer to the directory where the use Illuminate \ Http \ Request; use App \ Http \ the Controllers \ the Controller; use Illuminate \ Support \ Facades \ the Input; require_once ' the Classes / KenoBettingCheck.php ' ; class kenoBettingController the extends the Controller
Controller creates a show method
<?php namespace App\Http\Controllers; use App\User; use Illuminate\Http\Request; class UserController extends Controller { /** * 为指定用户显示详情 * * @param int $id * @return Response * @author LaravelAcademy.org */ public function show($id) { return view('user.profile', ['user' => User::findOrFail($id)]); } }
We can define the operation of the control point of the route like this: Note that this parameter is passed
Route::get('user/{id}', 'UserController@show');