Install
Installing Xampp and Laravel on Linux
composer create-project --prefer-dist laravel/laravel larave-react |
php artisan preset react |
Watch in development:
npm run watch |
数据库
工具:
Sequel Pro (for Mac OS)
phpmyadmin (for all OS)
修改 phpmyadmin 通过密码登陆:先在“账户”修改
root@localhost
的密码。然后将/opt/lamp/phpmyadmin/config.inc.php
的$cfg['Servers'][$i]['auth_type'] = 'config';
改成cookie
。[创建用户及赋予权限(https://www.cnblogs.com/lemon-flm/p/7597879.html)
create database if not exists laravel_reactjs default character set utf8 collate utf8_general_ci;
create user 'laravel'@'localhost';
grant all on laravel_reactjs.* to 'laravel'@'localhost' identified by '123456';
同步数据库
php artisan migrate |
如果出现如下提示:
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; |
原因:laravel改变了默认的数据库字符集,现在使用utf8mb4,如果你使用的MySQL数据库高于5.7就不会报错,如果低于该版本就会报错
解决方案:在
AppServiceProvider.php
添加代码:Schema::defaultStringLength(191);
完整的代码:
use Illuminate\Support\Facades\Schema;//一定要记得引入Schema |
将刚才建的表删除,重新运行:
$ php artisan migrate |
创建新表
php artisan make:migration create_blogs_table --create=blogs |
配置路由
routes/web.php
:
Route::get('/', function () { |
CRUD
php artisan make:model Blog |
https://www.youtube.com/watch?v=WYKSDrgk0fE&index=1&list=PLTXFz3WKxvNJZo1T0-ypVBWD0MfJtshav