Skip to content
Paulyoufu edited this page Nov 20, 2015 · 12 revisions

Welcome to the larvavel51 wiki! larvavel install curl -sS https://getcomposer.org/installer | php !/usr/bin/env php composer create-project laravel/laravel larvavel5 mv composer.phar /usr/local/bin/composer 开启服务器 php artisan serve 创建controllor php artisan make:controller SitesController

php artisan make:controller TestController —plain 创建空的控制器

数据库 php artisan migrate 创建数据库选择字符集 utf8_unicode_ci 配置mamp 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock’,

在数据库中创建表 php artisan make:migration create_articles_table --create=articles 向表里添加字段 php artisan make:migration add_into_column_to_articles --table=articles 引入包 composer require doctrine/dbal 第7节课 1创建数据模型 php artisan make:model Article 2进入命令行 php artisan tinker 3 创建article类 $article=new App\Article; 4 创建字段 $article->title='my first title’; $article->published_at=Carbon\Carbon::now() 有article类中就有以下字段

$article->toArray(); $first=App\Article::find(1); $first->title='Update' $first->save(); 查询 $second=App\Article::where('content','=','content')->get()

提交表单

$article=App\Article::create(['title'=>'Second Title','content'=>'Second Content','published_at'=>Carbon\Carbon::now()]); 视图views 所在目录 ../resources/views/yourview 第8节课 以前的内容复习 @foreach($articles as $article) @endforeach $article = Article::findOrFail($id); 超出范围会有提示 abort(404);显示错误页 第9节 添加form命令 composer require illuminate/html 配置文件 在app/config.php 找到数providers 最后一行添加 Illuminate\Html\HtmlServiceProvider::class, 在aliases 添加 'Form' => Illuminate\Html\FormFacade::class, form表单的语句 {!! Form::open() !!} {!! Form::text('name') !!} input {!! Form::close() !!} {!! Form::text('name',null,['class'=>'form']) !!} dd($request->all());//测试提交数据 $articles = Article::latest()->get();//将最新的文章放在最前面 dd($article->created_at->diffForHumans());//显示多少天之前 scopeYourFunctionName 在类中写方法 第11节 创建request php artisan make:request CreatEArticleRequest **authorize方法说明 ** 1发表的文章不能2来编辑 rules 放在控制器store方法里作参数Requests\CreateArticleRequest $request @if($error->any())

@foreach($errors->all() as $error)
  • {{ $error }}
  • Clone this wiki locally