初学laravel

配合postman 工具初学laravel

中文文档

 http://laravelacademy.org/post/2784.html

一、路由部分

laravel初始化的时候

 

先屏蔽这一行,然后进行路由测试

 

在routes.php里面写这些东西,然后一个一个测试

 

 

Route::get('/', function () {
   return view('welcome');
});
Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
    return $postId.'--'.$commentId;
});
Route::get('user_{name}', function ($name) {
    return $name;
});
Route::get('aa/{name}', function ($name) {
    return $name;
})->where('name', '[A-Za-z]+');
Route::get('user/{id}/{name}', function ($id, $name) {
    return $id.'--'.$name;
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);
//Route::get('/foo', function () {
//    echo  "get";
//});
//Route::post('/foo', function () {
//    echo  "post";
//});
//Route::put('/foo', function () {
//    echo  "put";
//});

 

 在post上面挨个调试即可

 

二、控制器部分

http://laravelacademy.org/post/2816.html

在http/controllers下面新建一个控制器IndexController.php

<?php

namespace App\Http\Controllers;

class IndexController extends Controller
{
    public function index(){
        echo "123";
    }
}

 

路由里面

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
   return view('welcome');
});

Route::get('test', 'IndexController@index');

访问http://www.blog.com/test

artisan创建控制器

php artisan make:controller UserController

 

 

 新建立控制器 分层

 

posted @ 2017-11-02 22:10  qingqing.li  阅读(126)  评论(0编辑  收藏  举报