企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1、列出所有可用命令 ~~~ php artisan list ~~~ 2、查看某个命令的帮助,可以使用`help`或`-h` ~~~ php artisan help migrate ~~~ 或 ~~~ php artisan migrate -h ~~~ 3、指定环境配置 ~~~ php artisan migrate --env=local ~~~ 4、查看当前laravel的版本 ~~~ php artisan --version ~~~ 或 ~~~ php artisan -V ~~~ 一.artisan命令 1.php artisan list //查看所有的artisan命令 2.php artisan help 命令 //查看指定命令的帮助,也可以这样用 php artisan 命令 --help或php artisan 命令 --h 3.php artisan --v 或 php artisan -V //查看当前安装的laravel版本 4.php artisan migrate --env=local //使用指定的环境配置,需要在执行命令时加上 --env即可切换 1.php artisan make:controller PagesController php artisan make:controller PagesController --resource 2.php artisan make:controller PagesController --hplp 3.php artisan make:controller PagesController --plain 4.php artisan fresh 5.php artisan migrate:rollback 6.php artisan make:migration create_articles_table --create="articles" 7.php artisan make:migration add_excerpt_to_articles_table 8.php artisan make:migration add_excerpt_to_articles_table --table="articles" 10.php artisan make:model Article -m (加-m参数会附加创建迁移文件) 11.php artisan tinker 12.php artisan make:controller ArticlesController --plain $article=new App\Article(); $article->published_at=Carbon\Carbon::now(); $article->toArray(); $article->toJson(); $article->save(); App\Article::all()->toArray(); App\Article::find(1); App\Article::where('body','Lorem ipsum')->get();//都是select,但返回的对象不同 App\Article::where('body','Lorem ipsum')->first();//都是select,但返回的对象不同 $article->body; $article=App\Article::create(['title'=>'New Article','body'=>'New body','published_at'=>Carbon\Carbon::now()]); $article=App\Article::find(2); $article->update(['body'=>'Updated Again']); protected $fillable=[ 'title', 'body', 'published_at' ] $article=Article::findOrFail($id); $article=Article::find($id); $article=Article::latest('published_at')->get(); $article=Article::order_by('published_at')->get(); 在phpstorm中,输入 ! 然后 tab键,就能自动填充 html代码 1.<?= $name; ?> 2.{{ $name }} 3.{!! $name !!} touch storage/database.sqlite $table->dropColumn('excerpt'); composer require illuminate/html //安装html模块 composer remove illuminate/html //移除html模块 1.php artisan help 2.php artisan list 3.php artisan make:model Article 4.php artisan migrate; 5.php artisan migrate:rollback; 6.composer dump-autoload 7.php artisan db:seed 8.php artisan route:list 9.php artisan migrate:rollback 10.php artisan tinker --help Route::group(['prefix'=>'admin','namespace'=>'Admin'],function(){ Route::get('/','AdminHomeController@index'); }); $table->increments('id'); $table->string('name'); $table->string('email', 64); $table->char('char', 64); $table->string('email')->unique(); $table->string('image')->nullable(); $table->text('body')->nullable(); $table->integer('user_id'); $table->boolean('active')->default(1); $table->integer('role_id')->unsigned(); ``` $table->string('password',32) ->deafault('')//默认值 ->comment('密码');//注释 $table->integer('created_at') ->default('0') ->unsigned(); $table->integer('updated_at')->unsigned(); ``` $table->rememberToken(); $table ->dropColumn('email'); get('/','IndexController@index')==Route::get('/','IndexController@index') dd(); php artisan tinker DB::table('songs')->insert(['title'=>'As Long As You Love Me']); DB::table('songs')->get(); DB::table('songs')->find(['id'=>1]); $song=new App\Song; $song->title="As Long As You Love Me"; $song->slug="as long as you love me"; $song->toArray(); $song->save(); $song->all(); $song->all()->toArray(); $song->all()->toJson(); Song::whereSlug($slug)->first(); Route::model('song','App\Song'); Route::bind('song',function($slug){ //return App\Song::whereSlug($slug)->first(); return App\Song::where('slug',$slug)->first(); }); compose require illuminate/html {!! Form::open() !!} {!! Form::close() !!} {!! Form::text('title') !!} {!! Form::text('title',null,['class'=>'form-control']) !!} {!! Form::textarea('lyrics',null,['class'=>'form-control']) !!} {!! Form::submit('Update Song',['class'=>'btn btn-primary']) !!} {!! Form::model($song,['url'=>'http://www.baidu.com','method'=>'post']) !!} dd(\Request::input()); dd(\Request::all()); redirect('songs'); $song->fill(['title'=>$request->get('title')])->save(); protected $fillable=['title','lyrics']; $router->get('songs','SongsController@index'); php artisan route:list $router->resource('songs','SongsController'); $router->resource('songs','SongsController',[ //'only'=>['index','show','edit','update'], 'except'=>['create'] ]); route('song_path',['$song->title']); {!! link_to_route('song_path',$song->title,[$song->title]) !!} {!! link_to_route('show.index',$song->title,[$song->title]) !!} {!! Form::model($song,['route'=>['songs.update',$song->title],'method'=>'PATCH']) !!} @include('songs.form') php artisan | grep make {{$errors->has('title') ? 'has-error' : ''}} {!! $errors->first('title','<span class="help-block">:message</span>') !!} php artisan make:seeder StudentTableSeeder php artisan db:seed --class=StudentTableSeeder laravel 自定义函数 可以写在routes.php里,这样可以自动加载,但是这不是标准的做法 应该写在一个独立的php文件里,然后通过配置conposer.json这个文件,达到自动加载的效果 步骤: 1.在app/Http下建立helper.php(当然也可以命名为其他名字),把函数写在这个文件里 2.打开conposer.json,找到 "psr-4": { "App\\": "app/" }这一项,在下面添加,如下些所示 "files":["app/Http/helper.php"] 3.然后在命令行模式下,运行 composer dump-autoload 命令刷新配置项 这样就可以了