DB_HOST=127.0.0.1 //连接地址不使用localhost DB_DATABASE=homestead //数据库名称(需要预先创建) DB_USERNAME=root //登录名 DB_PASSWORD= //密码
php artisan make:migration create_articles_table --create=articles
public function up() {
Schema::create('articles', function (Blueprint $table) { $table->increments('id');// 主键 自增
$table->string('title');
$table->text('intro');
$table->text('content');
$table->timestamp('published_at');
$table->timestamps(); // 自动创建的两个字段:created_at 和 updated_at });
}
php artisan migrate
php artisan make:model Article
namespace App\Http\Controllers\Articles;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Article;//这个必须有,引入model,不然无法获取数据库数据
class ArticlesController extends Controller{
public function index(){
// $articles = Article::with('category')->latest()->paginate(15);
$articles = Article::all();//获取所有数据
//print_r($articles);
$name = array(
0=>array(
"name"=>"123"
),
);
return view('articles.index', compact('articles'));//映射
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有