zoukankan      html  css  js  c++  java
  • 初学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 AppHttpControllers;
    
    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

     

     

     新建立控制器 分层

  • 相关阅读:
    ionic3开发环境搭建与配置(win10系统)
    angular4打包以后,刷新报404
    css3文字渐变无效果的解决方案
    node-sass安装失败的解决方案
    python logging 重复写日志问题
    进程和线程的概念
    软件开发目录规范
    相对导入
    python引入导入自定义模块和外部文件
    异常处理
  • 原文地址:https://www.cnblogs.com/php0916/p/7774831.html
Copyright © 2011-2022 走看看