更新Composer

composer self-update 
composer -V
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer

Laravel安装

composer create-project --prefer-dist laravel/laravel blog
cd blog/
composer require laravel/ui
php artisan serve --port=8080
http://127.0.0.1:8080/

生成Home控制器

php artisan make:controller HomeController

配置路由   blog\app\routes\web.php

<?phpuse Illuminate\Support\Facades\Route;/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/Route::get('/', function () {return view('welcome');
});//新增条目
Route::get('hello',function(){return 'hello,Laravel8';
});

访问路由

http://localhost/hello

修改HomeController

<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;class HomeController extends Controller
{//public function index(){return "index...";}
}

修改路由

<?phpuse Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/Route::get('/', function () {return view('welcome');
});//新增条目
Route::get('hello',function(){return 'hello,Laravel8';
});Route::get('/home', [HomeController::class, 'index']);

访问路由

http://localhost/home

配置Nginx伪静态

location / {              if (!-e $request_filename) {             rewrite  ^/(.*)$  /index.php/$1  last;      break;  }   }

初始化bootstrap

php artisan ui bootstrap
npm install

应用

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>首页</title><link rel="stylesheet" type="text/css" href="css/app.css"><script type="text/javascript" src="js/app.js"></script>
</head><body><h2>首页</h2><div><!-- 标准的按钮 --><button type="button" class="btn btn-default">默认按钮</button><!-- 提供额外的视觉效果,标识一组按钮中的原始动作 --><button type="button" class="btn btn-primary">原始按钮</button><!-- 表示一个成功的或积极的动作 --><button type="button" class="btn btn-success">成功按钮</button><!-- 信息警告消息的上下文按钮 --><button type="button" class="btn btn-info">信息按钮</button><!-- 表示应谨慎采取的动作 --><button type="button" class="btn btn-warning">警告按钮</button><!-- 表示一个危险的或潜在的负面动作 --><button type="button" class="btn btn-danger">危险按钮</button><!-- 并不强调是一个按钮,看起来像一个链接,但同时保持按钮的行为 --><button type="button" class="btn btn-link">链接按钮</button></div>
<br>
<nav aria-label="...">
<ul class="pagination"><li class="page-item"><a class="page-link" href="#">&laquo;</a></li><br><li class="page-item"><a class="page-link" href="#">1</a></li><br><li class="page-item"><a class="page-link" href="#">2</a></li><br><li class="page-item"><a class="page-link" href="#">3</a></li><br><li class="page-item"><a class="page-link" href="#">4</a></li><br><li class="page-item"><a class="page-link" href="#">5</a></li><br><li class="page-item"><a class="page-link" href="#">&raquo;</a></li>
</ul>
</nav><br> </body>

配置AppServiceProvider

<?phpnamespace App\Providers;use Illuminate\Support\ServiceProvider;use Illuminate\Support\Facades\Schema;
use Illuminate\Pagination\Paginator;class AppServiceProvider extends ServiceProvider
{/*** Register any application services.** @return void*/public function register(){//}/*** Bootstrap any application services.** @return void*/public function boot(){//Laravel 更改了默认数据库字符集,为utf8mb4,其中包括对存储表情符号的支持。 如果数据库运行的是MySQL v5.7.7及更高版本,则没有问题;对于那些运行MariaDB或更旧版本的MySQL的用户,在尝试运行迁移时可能会遇到这个错误。 Schema::defaultStringLength(191);Paginator::useBootstrap();}
}
Schema::defaultStringLength(191);

数据迁移

php artisan migrate  
php artisan  migrate:install
php artisan make:migration create_post_table

blog---->database---->migrations

<?phpuse Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;class CreatePostsTable extends Migration
{/*** Run the migrations.** @return void*/public function up(){Schema::create('posts', function (Blueprint $table) {$table->increments('id');$table->string('title',255)->default("");$table->text('content');$table->integer('user_id')->default(0);$table->timestamps();});}/*** Reverse the migrations.** @return void*/public function down(){Schema::dropIfExists('posts');}
}

查询帮助

php artisan help migrate 

生成 App Key

php artisan key:generate  

生成控制器

php artisan make:controller    

生成模型

php artisan make:model   

生成授权策略

php artisan make:policy       

生成 Seeder 文件

php artisan make:seeder            

回滚迁移

php artisan migrate:rollback   

重置数据库

php artisan migrate:refresh    

填充数据库

php artisan db:seed

查看路由列表

php artisan route:list           

生成factory

php artisan make:factory PostFactory
<?phpnamespace Database\Factories;use Illuminate\Database\Eloquent\Factories\Factory; class PostFactory extends Factory
{/*** Define the model's default state.** @return array*/public function definition(){return ['title' => $this->faker->sentence(6),'content' => $this->faker->paragraph(10),];}}

进入 tinker 环境

php artisan tinker  
App\Models\Post::factory()->count(5)->create()

Laravel8入门相关推荐

  1. laravel入门及技术指南

    介绍 Laravel 是一套简洁.优雅的PHP Web开发框架(PHP Web Framework).它可以让你从面条一样杂乱的代码中解脱出来:它可以帮你构建一个完美的网络APP,而且每行代码都可以简 ...

  2. 用Construct 2制作入门小游戏~

    今天在软导课上了解到了Construct 2这个神器,本零基础菜鸟决定尝试做一个简单的小游戏(实际上是入门的教程啊= = 首先呢,肯定是到官网下载软件啊,点击我下载~ 等安装完毕后我便按照新手教程开始 ...

  3. Docker入门六部曲——Swarm

    原文链接:http://www.dubby.cn/detail.html?id=8738 准备工作 安装Docker(版本最低1.13). 安装好Docker Compose,上一篇文章介绍过的. 安 ...

  4. Docker入门六部曲——Stack

    原文链接:http://www.dubby.cn/detail.html?id=8739 准备知识 安装Docker(版本最低1.13). 阅读完Docker入门六部曲--Swarm,并且完成其中介绍 ...

  5. Docker入门六部曲——服务

    原文链接:http://www.dubby.cn/detail.html?id=8735 准备 已经安装好Docker 1.13或者以上的版本. 安装好Docker Compose.如果你是用的是Do ...

  6. 【springboot】入门

    简介: springBoot是spring团队为了整合spring全家桶中的系列框架做研究出来的一个轻量级框架.随着spring4.0推出而推出,springBoot可以説是J2SEE的一站式解决方案 ...

  7. SpringBoot (一) :入门篇 Hello World

    什么是SpringBoot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不 ...

  8. 入门指南目录页 -PaddlePaddle 飞桨 入门指南 FAQ合集-深度学习问题

    入门指南目录页 -PaddlePaddle 飞桨 入门指南 FAQ合集 GT_Zhang关注 0.1012019.08.01 18:43:34字数 1,874阅读 795 Hi,欢迎各位来自Paddl ...

  9. 5 分钟入门 Google 最强NLP模型:BERT

    BERT (Bidirectional Encoder Representations from Transformers) 10月11日,Google AI Language 发布了论文 BERT: ...

最新文章

  1. 网站建设难?三个技巧来帮你!
  2. webstorm+nodejs+JetBrains IDE Support+chrome打造前端开发神器
  3. 蔚来回应庄莉离职:不会因少数人员的正常流动受到影响
  4. postman与Jmeter调用接口
  5. 【Selenium2】【Shell】
  6. linux系统网络命令(六)
  7. 机器学习 深度学习 ai_什么是AI? 从机器学习到决策自动化
  8. 开源微服务框架 汇总
  9. ps制作动态html,PS制作动态海报教程
  10. 《基于卷积神经网络(CNN)的网络流量分类》优秀本科毕设实验总结
  11. 老旧笔记本的WIN10系统安装Win7还是Win8版本声卡驱动?
  12. Python让你的终端输出变得五彩斑斓
  13. android学习笔记之——获取SD卡及手机ROM容量
  14. linux常见桌面系统以及安装gnome远程桌面
  15. modbustcp测试工具怎么用_年轻人不讲武德不仅白piao接口测试知识还白piao接口测试工具会员...
  16. Linux系统获取开发板的文件系统并打包成img文件
  17. 【毕业设计源码】基于微信小程序的查寝系统的设计与实现
  18. mathcad入门二
  19. elementui 按钮 表单_仿ElementUI实现一个Form表单的实现代码
  20. 升级华为笔记本U盘安装盘

热门文章

  1. 组织健康度是什么?组织架构调整是实现组织健康的良药吗?
  2. 芯片量产测试常用“黑话”
  3. UTF8 转GB 中文字符
  4. You may use special comments to disable some warnings.报错解决
  5. SAML2.0 笔记(二)
  6. JAVA数组拼接 join_在 Java 中如何使用 join 方法连接多个字符串?
  7. C++ 中 什么时候不用new?什么时候用new?
  8. linux中修改权限命令,Linux如何用命令修改权限
  9. 压缩解压命令(gzip、gunzip | tar | zip、unzip | bzip2、bunzip2)
  10. 最新uniapp 微信小程序获取头像操作指南