{{--命令--}}
使用composer下載laravel
composer create-project laravel/laravel --prefer-dist 項(xiàng)目名稱
創(chuàng)建控制器
php artisan make:controller 控制器名稱
創(chuàng)建模型
php artisan make:model 模型名稱
指定路徑:
php artisan make:model Http\Model\模型名稱
創(chuàng)建中間件
php artisan make:middleware 中間件名稱
composer install
install 命令從當(dāng)前目錄讀取 composer.json 文件,處理了依賴關(guān)系,并把其安裝到 vendor 目錄下惨远。
{{--數(shù)據(jù)庫遷移--}}
生成遷移
php artisan make:migration create_users_table
創(chuàng)建表
Schema::create('links', function (Blueprint $table){
$table->engine = 'MyISAM';//設(shè)置表的存儲引擎
$table->increments('link_id');//數(shù)據(jù)庫主鍵自增ID
$table->string('link_name', 50)->default('')->comment('//名稱');
$table->string('link_title', 100)->default('')->comment('//標(biāo)題');
$table->string('link_url', 100)->default('')->comment('//地址');
$table->integer('link_order')->default(0)->comment('//排序');
});
Schema::drop('links');
運(yùn)行遷移
php artisan migrate
回滾遷移
migrate:reset命令將會回滾所有的應(yīng)用遷移
{{--Route--}}
常規(guī)路由
Route::any('admin', 'Admin\LoginController@login');
中間件路由
Route::group(['middleware' => ['web','admin.login']],function (){
Route::any('admin/index', 'Admin\IndexController@index');
});
中間件、前綴则吟、命名空間路由
Route::group(['middleware' => ['web','admin.login'], 'prefix' => 'admin', 'namespace' => 'Admin'],function (){
Route::any('index', 'IndexController@index');
});
{{--Model--}}
設(shè)置表名稱
protected $table = 'user';
設(shè)置主鍵字段
protected $primaryKey = 'user_id';
禁止自動加載時(shí)間
public $timestamps = false;
{{--函數(shù)使用--}}
入口文件開啟session
session_start
重定向
return redirect('admin/index');
加密
Crypt::encrypt('123456');
解密
Crypt::decrypt('字符串');
清除session
session(['user' => null]);
獲取表單提交數(shù)據(jù)除某個(gè)字段
$input = Input::except('_token');
分頁
$data = Article::paginate(10);
調(diào)用分頁
{{$data->links()}}
{{--模板文件--}}
在*.blade.php引用css/js文件
{{asset('css/style.css');}}
表單提交csrf驗(yàn)證
{{csrf_field()}} (生成一個(gè)hidden類型的input)
{{csrf_token()}} (僅生成csrf)
公共文件允許修改的位置
@yield('content')
繼承公共文件
@extends('layous.admin')
修改內(nèi)容
@section('content')參數(shù)必須跟@yield的參數(shù)一致
@endsection
/********************查***********************/
獲取所有數(shù)據(jù)
$this->all();
獲取主鍵id為1的數(shù)據(jù)
$this->find(1);
獲取主鍵id為4的數(shù)據(jù),如果沒有數(shù)據(jù)就報(bào)錯(cuò)
$this->findOrFail(4);
獲取username是menhaopeng的數(shù)據(jù)
$this->where('name','menhaopeng')->get();
獲取id大于1的數(shù)據(jù)
$this-where('id','>',1)->get();
/********************增***********************/
$user_data = ['name' => 'user2', 'age' => 28];
$this->fill($user_data);
$this->save();
/********************改***********************/
//修改id為14的數(shù)據(jù)
$user = $this->find(14);
$user->name = 'zhangsan';
$user->age = 50;
$user->save();
//修改id小于8的數(shù)據(jù)
$users = $this->where('id','<',8);
$users->update(['name' => 'zhangsan', 'age' => 50]);
/********************改***********************/
//刪除id為15的數(shù)據(jù)
$user = $this->find(15);
$user->delete();