成人怡红院-成人怡红院视频在线观看-成人影视大全-成人影院203nnxyz-美女毛片在线看-美女免费黄

站長資訊網(wǎng)
最全最豐富的資訊網(wǎng)站

新鮮出爐的Laravel 速查表不要錯過!

下面由Laravel教程欄目帶大家介紹新鮮出爐的Laravel 速查表,希望對大家有所幫助!


Laravel 速查表

項目命令

// 創(chuàng)建新項目 $ laravel new projectName  // 運行 服務(wù)/項目 $ php artisan serve  // 查看指令列表 $ php artisan list  // 幫助 $ php artisan help migrate  // Laravel 控制臺 $ php artisan tinker  // 查看路由列表 $ php artisan route:list

公共指令

// 數(shù)據(jù)庫遷移 $ php artisan migrate  // 數(shù)據(jù)填充 $ php artisan db:seed  // 創(chuàng)建數(shù)據(jù)表遷移文件 $ php artisan make:migration create_products_table  // 生成模型選項:  // -m (migration), -c (controller), -r (resource controllers), -f (factory), -s (seed) $ php artisan make:model Product -mcf  // 生成控制器 $ php artisan make:controller ProductsController  // 表更新字段 $ php artisan make:migration add_date_to_blogposts_table  // 回滾上一次遷移 php artisan migrate:rollback  // 回滾所有遷移 php artisan migrate:reset  // 回滾所有遷移并刷新 php artisan migrate:refresh  // 回滾所有遷移,刷新并生成數(shù)據(jù) php artisan migrate:refresh --seed

創(chuàng)建和更新數(shù)據(jù)表

// 創(chuàng)建數(shù)據(jù)表 $ php artisan make:migration create_products_table  // 創(chuàng)建數(shù)據(jù)表(遷移示例) Schema::create('products', function (Blueprint $table) {     // 自增主鍵     $table->id();     // created_at 和 updated_at 字段     $table->timestamps();     // 唯一約束     $table->string('modelNo')->unique();     // 非必要     $table->text('description')->nullable();     // 默認(rèn)值     $table->boolean('isActive')->default(true);      // 索引     $table->index(['account_id', 'created_at']);     // 外鍵約束     $table->foreignId('user_id')->constrained('users')->onDelete('cascade'); });  // 更新表(遷移示例) $ php artisan make:migration add_comment_to_products_table  // up() Schema::table('users', function (Blueprint $table) {     $table->text('comment'); });  // down() Schema::table('users', function (Blueprint $table) {     $table->dropColumn('comment'); });

模型

// 模型質(zhì)量指定列表排除屬性 protected $guarded = []; // empty == All  // 或者包含屬性的列表 protected $fillable = ['name', 'email', 'password',];  // 一對多關(guān)系 (一條帖子對應(yīng)多條評論) public function comments()  {     return $this->hasMany(Comment:class);  }  // 一對多關(guān)系 (多條評論在一條帖子下)  public function post()  {                                 return $this->belongTo(Post::class);  }  // 一對一關(guān)系 (作者和個人簡介) public function profile()  {     return $this->hasOne(Profile::class);  }  // 一對一關(guān)系 (個人簡介和作者)  public function author()  {                                 return $this->belongTo(Author::class);  }  // 多對多關(guān)系 // 3 張表 (帖子, 標(biāo)簽和帖子-標(biāo)簽) // 帖子-標(biāo)簽:post_tag (post_id, tag_id)  // 「標(biāo)簽」模型中... public function posts()     {         return $this->belongsToMany(Post::class);     }  // 帖子模型中... public function tags()     {         return $this->belongsToMany(Tag::class);     }

Factory

// 例子: database/factories/ProductFactory.php public function definition() {     return [         'name' => $this->faker->text(20),         'price' => $this->faker->numberBetween(10, 10000),     ]; } // 所有 fakers 選項 : https://github.com/fzaninotto/Faker

Seed

// 例子: database/seeders/DatabaseSeeder.php public function run() {     Product::factory(10)->create(); }

運行 Seeders

$ php artisan db:seed // 或者 migration 時執(zhí)行 $ php artisan migrate --seed

Eloquent ORM

// 新建  $flight = new Flight; $flight->name = $request->name; $flight->save();  // 更新  $flight = Flight::find(1); $flight->name = 'New Flight Name'; $flight->save();  // 創(chuàng)建 $user = User::create(['first_name' => 'Taylor','last_name' => 'Otwell']);   // 更新所有:   Flight::where('active', 1)->update(['delayed' => 1]);  // 刪除  $current_user = User::Find(1) $current_user.delete();   // 根據(jù) id 刪除:   User::destroy(1);  // 刪除所有 $deletedRows = Flight::where('active', 0)->delete();  // 獲取所有 $items = Item::all().   // 根據(jù)主鍵查詢一條記錄 $flight = Flight::find(1);  // 如果不存在顯示 404 $model = Flight::findOrFail(1);   // 獲取最后一條記錄 $items = Item::latest()->get()  // 鏈?zhǔn)? $flights = AppFlight::where('active', 1)->orderBy('name', 'desc')->take(10)->get();  // Where Todo::where('id', $id)->firstOrFail()    // Like  Todos::where('name', 'like', '%' . $my . '%')->get()  // Or where Todos::where('name', 'mike')->orWhere('title', '=', 'Admin')->get();  // Count $count = Flight::where('active', 1)->count();  // Sum $sum = Flight::where('active', 1)->sum('price');  // Contain? if ($project->$users->contains('mike'))

路由

// 基礎(chǔ)閉包路由 Route::get('/greeting', function () {     return 'Hello World'; });  // 視圖路由快捷方式 Route::view('/welcome', 'welcome');  // 路由到控制器 use AppHttpControllersUserController; Route::get('/user', [UserController::class, 'index']);  // 僅針對特定 HTTP 動詞的路由 Route::match(['get', 'post'], '/', function () {     // });  // 響應(yīng)所有 HTTP 請求的路由 Route::any('/', function () {     // });  // 重定向路由 Route::redirect('/clients', '/customers');  // 路由參數(shù) Route::get('/user/{id}', function ($id) {     return 'User '.$id; });  // 可選參數(shù) Route::get('/user/{name?}', function ($name = 'John') {     return $name; });  // 路由命名 Route::get(     '/user/profile',     [UserProfileController::class, 'show'] )->name('profile');  // 資源路由 Route::resource('photos', PhotoController::class);  GET /photos index   photos.index GET /photos/create  create  photos.create POST    /photos store   photos.store GET /photos/{photo} show    photos.show GET /photos/{photo}/edit    edit    photos.edit PUT/PATCH   /photos/{photo} update  photos.update DELETE  /photos/{photo} destroy photos.destroy  // 完整資源路由 Route::resource('photos.comments', PhotoCommentController::class);  // 部分資源路由 Route::resource('photos', PhotoController::class)->only([     'index', 'show' ]);  Route::resource('photos', PhotoController::class)->except([     'create', 'store', 'update', 'destroy' ]);  // 使用路由名稱生成 URL $url = route('profile', ['id' => 1]);  // 生成重定向... return redirect()->route('profile');  // 路由組前綴 Route::prefix('admin')->group(function () {     Route::get('/users', function () {         // Matches The "/admin/users" URL     }); });  // 路由模型綁定 use AppModelsUser; Route::get('/users/{user}', function (User $user) {     return $user->email; });  // 路由模型綁定(id 除外) use AppModelsUser; Route::get('/posts/{post:slug}', function (Post $post) {     return view('post', ['post' => $post]); });  // 備選路由 Route::fallback(function () {     // });

緩存

// 路由緩存 php artisan route:cache  // 獲取或保存(鍵,存活時間,值) $users = Cache::remember('users', now()->addMinutes(5), function () {     return DB::table('users')->get(); });

控制器

// 設(shè)置校驗規(guī)則 protected $rules = [     'title' => 'required|unique:posts|max:255',     'name' => 'required|min:6',     'email' => 'required|email',     'publish_at' => 'nullable|date', ];  // 校驗 $validatedData = $request->validate($rules)  // 顯示 404 錯誤頁 abort(404, 'Sorry, Post not found')  // Controller CRUD 示例 Class ProductsController {     public function index()    {        $products = Product::all();         // app/resources/views/products/index.blade.php        return view('products.index', ['products', $products]);     }     public function create()    {        return view('products.create');    }     public function store()    {        Product::create(request()->validate([            'name' => 'required',            'price' => 'required',            'note' => 'nullable'        ]));         return redirect(route('products.index'));    }     // 模型注入方法    public function show(Product $product)    {        return view('products.show', ['product', $product]);     }     public function edit(Product $product)    {        return view('products.edit', ['product', $product]);     }     public function update(Product $product)    {        Product::update(request()->validate([            'name' => 'required',            'price' => 'required',            'note' => 'nullable'        ]));         return redirect(route($product->path()));    }     public function delete(Product $product)    {         $product->delete();         return redirect("/contacts");    } }  // 獲取 Query Params www.demo.html?name=mike request()->name //mike  // 獲取 Form data 傳參(或默認(rèn)值) request()->input('email', 'no@email.com')

Template

<!-- 路由名 --> <a href="{{ route('routeName.show', $id) }}">  <!-- 模板繼承 --> @yield('content')  <!-- layout.blade.php --> @extends('layout') @section('content') … @endsection  <!-- 模板 include --> @include('view.name', ['name' => 'John'])  <!-- 模板變量 --> {{ var_name }}   <!-- 原生安全模板變量 -->  { !! var_name !! }  <!-- 迭代 --> @foreach ($items as $item)    {{ $item.name }}    @if($loop->last)         $loop->index     @endif @endforeach  <!-- 條件 --> @if ($post->id === 1)      'Post one'  @elseif ($post->id === 2)     'Post two!'  @else      'Other'  @endif  <!--Form 表單 --> <form method="POST" action="{{ route('posts.store') }}">  @method(‘PUT’) @csrf  <!-- Request 路徑匹配 --> {{ request()->is('posts*') ? 'current page' : 'not current page' }}   <!-- 路由是否存在 --> @if (Route::has('login'))  <!-- Auth blade 變量 --> @auth  @endauth  @guest  <!-- 當(dāng)前用戶 --> {{ Auth::user()->name }}  <!-- Validations 驗證錯誤 --> @if ($errors->any())     <p class="alert alert-danger">         <ul>             @foreach ($errors->all() as $error)                 <li>{{ $error }}</li>             @endforeach         </ul>     </p> @endif  <!-- 檢查具體屬性 --> <input id="title" type="text" class="@error('title') is-invalid @enderror">  <!-- 上一次請求數(shù)據(jù)填充表單 --> {{ old('name') }}

不使用模型訪問數(shù)據(jù)庫

use IlluminateSupportFacadesDB; $user = DB::table('users')->first(); $users = DB::select('select name, email from users'); DB::insert('insert into users (name, email, password) value(?, ?, ?)', ['Mike', 'mike@hey.com', 'pass123']); DB::update('update users set name = ? where id = 1', ['eric']); DB::delete('delete from users where id = 1');

幫助函數(shù)

// 顯示變量內(nèi)容并終止執(zhí)行 dd($products)  // 將數(shù)組轉(zhuǎn)為Laravel集合 $collection = collect($array);  // 按描述升序排序 $ordered_collection = $collection->orderBy(‘description’);  // 重置集合鍵 $ordered_collection = $ordered_collection->values()->all();  // 返回項目完整路徑 app : app_path(); resources : resource_path(); database :database_path();

閃存 和 Session

// 閃存(只有下一個請求) $request->session()->flash('status', 'Task was successful!');  // 帶重定向的閃存 return redirect('/home')->with('success' => 'email sent!');  // 設(shè)置 Session $request->session()->put('key', 'value');  // 獲取 session $value = session('key'); If session: if ($request->session()->has('users'))  // 刪除 session $request->session()->forget('key');  // 在模板中顯示 flash @if (session('message')) {{ session('message') }} @endif

HTTP Client

// 引入包 use IlluminateSupportFacadesHttp;  // Http get 方式請求 $response = Http::get('www.thecat.com') $data = $response->json()  // Http get 帶參方式請求 $res = Http::get('www.thecat.com', ['param1', 'param2'])  // Http post 帶請求體方式請求 $res = Http::post('http://test.com', ['name' => 'Steve','role' => 'Admin']);  // 帶令牌認(rèn)證方式請求 $res = Http::withToken('123456789')->post('http://the.com', ['name' => 'Steve']);  // 帶請求頭方式發(fā)起請求 $res = Http::withHeaders(['type'=>'json'])->post('http://the.com', ['name' => 'Steve']);

Storage (用于存儲在本地文件或者云端服務(wù)的助手類)

// Public 驅(qū)動配置: Local storage/app/public Storage::disk('public')->exists('file.jpg'))  // S3 云存儲驅(qū)動配置: storage: 例如 亞馬遜云: Storage::disk('s3')->exists('file.jpg'))   // 在 web 服務(wù)中暴露公共訪問內(nèi)容 php artisan storage:link  // 在存儲文件夾中獲取或者保存文件 use IlluminateSupportFacadesStorage; Storage::disk('public')->put('example.txt', 'Contents'); $contents = Storage::disk('public')->get('file.jpg');   // 通過生成訪問資源的 url  $url = Storage::url('file.jpg'); // 或者通過公共配置的絕對路徑 <img src={{ asset('storage/image1.jpg') }}/>  // 刪除文件 Storage::delete('file.jpg');  // 下載文件 Storage::disk('public')->download('export.csv');

從 github 安裝新項目

$ git clone {project http address} projectName $ cd projectName $ composer install $ cp .env.example .env $ php artisan key:generate $ php artisan migrate $ npm install

Heroku 部署

// 本地(MacOs)機(jī)器安裝 Heroku  $ brew tap heroku/brew && brew install heroku  // 登陸 heroku (不存在則創(chuàng)建) $ heroku login  // 創(chuàng)建 Profile  $ touch Profile  // 保存 Profile web: vendor/bin/heroku-php-apache2 public/

Rest API (創(chuàng)建 Rest API 端點)

API 路由 ( 所有 api 路由都帶 'api/' 前綴 )

// routes/api.php Route::get('products', [AppHttpControllersProductsController::class, 'index']); Route::get('products/{product}', [AppHttpControllersProductsController::class, 'show']); Route::post('products', [AppHttpControllersProductsController::class, 'store']);

API 資源 (介于模型和 JSON 響應(yīng)之間的資源層)

$ php artisan make:resource ProductResource

資源路由定義文件

// app/resource/ProductResource.php public function toArray($request)     {         return [             'id' => $this->id,             'name' => $this->name,             'price' => $this->price,             'custom' => 'This is a custom field',         ];     }

API 控制器 (最佳實踐是將您的 API 控制器放在 app/Http/Controllers/API/v1/中)

public function index() {         //$products = Product::all();         $products = Product::paginate(5);         return ProductResource::collection($products);     }      public function show(Product $product) {         return new ProductResource($product);     }      public function store(StoreProductRequest $request) {         $product = Product::create($request->all());         return new ProductResource($product);     }

API 令牌認(rèn)證

首先,您需要為特定用戶創(chuàng)建一個 Token。【

贊(0)
分享到: 更多 (0)
?
網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號
草莓视频午夜在线观影| 99大香伊乱码一区二区| 尤物AV无码国产在线看| 最新国产乱人伦偷精品免费网站| 52秋霞东北熟女叫床| CHINESEMATURE性老| 成人中文乱幕日产无线码| 国产办公室秘书无码精品99| 国精产品一码二码三M| 久久精品国产一区二区三区| 男人扒开女人的腿做爽爽视频| 人妻 日韩精品 中文字幕| 少妇被躁爽到呻吟全过的小说| 玩弄粉嫩少妇高潮出白浆AⅤ| 亚洲AV成人男人的天堂手机| 亚洲综合色AAA成人无码| 99国精产品品质溯源网| 大胸年轻继拇HD无码| 国精产品一区二区三区四区糖心| 久久人人爽人人爽人人AV| 强壮公弄得我次次高潮小说| 玩弄中国白嫩少妇HD乱| 亚洲色大成网站WWW看下面| 中文字幕久久精品波多野结百度| 成年免费A级毛片免费看| 国产午夜福利短视频在线观看| 久久久精品国产SM最大网站 | 永久免费观看美女裸体的网站| JAPANESE中国丰满少妇| 国产精品一区二区国产馆蜜桃 | 国产亚洲AV手机在线观看| 久久久久亚洲AV成人片乱码| 人妻少妇乱孑伦无码专区蜜柚 | 人妻夜夜爽天天爽三区麻豆AV网| 无码一区二区三区AⅤ免费蜜桃视| 亚洲中文无码a∨在线观看| 被粗大噗嗤噗嗤进出灌满浓浆| 国产亚洲成AV人片在线观黄桃| 麻豆熟妇人妻XXXXXX| 少妇被躁爽到呻吟全过的小说| 亚洲无人区码一码二码三码的含义| あざらしそふと官网| 国产一区精选播放022| 男女高潮又爽又黄又无遮挡| 无码熟妇人妻AV在线影院| 又粗又大又黄又爽的免费视频| 丰满人妻妇伦又伦精品App抖| 久久99国产精品久久99软件| 人人爽人人操人人精品| 亚洲精品无码永久在线观看男男| 扒开双腿疯狂进出爽爽爽视频| 后进式疯狂摇乳无遮挡GIF| 欧美最猛黑人XXXⅩ猛男欧| 亚洲AV无码一区二区三区蜜桃| BDB14黑人巨大视频| 韩国三级HD中文字幕| 人妻少妇性色精品专区av| 亚洲国产AV高清无码| 成年网站未满十八禁在线观看| 精品性高朝久久久久久久| 日日狠狠久久偷偷色综合免费 | 国产精品美女WWW爽爽爽视频 | 少妇午夜福利一区二区| 涨乳催乳改造调教公主| 国产女主播高潮在线播放| 欧美中日韩免费观看网站| 亚洲乱色熟女一区二区三区蜜臀 | GOGO人体GOGO西西大尺度| 精品国产18久久久久久| 色欲久久九色一区二区三区| 中文字幕日韩一区二区不卡| 国产香蕉97碰碰视频VA碰碰看| 青青草视频 成人| 亚洲日韩欧美一区久久久久我| 国产99精品视频一区二区三区| 麻花豆传媒剧国产MV入口| 亚洲AV无码潮喷在线观看| 出租房里的交互高康张睿| 美女黑人做受XXXXXⅩ性| 亚洲AⅤ天堂AV天堂无码| 刺激Chinese乱叫国产高潮| 蜜桃亚洲AV无码一区二区三区| 亚洲AV怡红院AV男人的天堂| 丰满少妇A级毛片| 欧美老熟妇乱人伦人妻| 亚洲伊人色欲综合网| 国内精品视频一区二区三区八戒| 色婷婷综合久久久久中文字幕| A∨色狠狠一区二区三区| 久久精品AⅤ无码中文字字幕重口| 无码人妻一区二区三区四区AV| 草莓视频APP无限观看| 女儿国在线观看免费版高清| 亚洲色偷偷偷网站色偷一区人人藻| 国产精品亚洲综合网熟女| 色8久久人人97超碰香蕉987| YY8090福利午夜理论片| 蜜臀AV免费一区二区三区| 亚洲一区二区三区无码久久| 国产一区二区三区美女| 婷婷97狠狠色综合| 吃瓜视频最全观看| 强行无套内谢大学生初次| 337P日本欧洲亚洲大胆在线| 久久综合九色欧美综合狠狠| 亚洲精品无码AV人在线播放| 国产偷国产偷亚洲清高网站 | 国产福利一区二区精品秒拍| 日韩揉捏奶头高潮不断视频| BBW下身丰满18XXXX| 男人躁女人到高潮视频| 制服丝袜另类专区制服| 久久久久久久久毛片精品| 亚洲精品无码AV专区最新 | 丁香婷婷在线成人播放视频| 日本丰满护士爆乳XXXX无遮挡| AV天堂影音先锋AV色资源网站| 蜜桃AV少妇久久久久久高潮不断| 野花社区高清在线观看视频| 久久国产乱子伦免费精品无码| 亚洲国产成人无码AV在线| 黑人性狂欢在线播放| 亚洲精品国产AV天美传媒| 极品无码AV国模在线观看| 亚洲国产精品久久久久婷婷软件| 韩国好看女性高级感美妆| 亚洲AV片无码久久尤物| 韩国乱码片免费看| 亚洲成AV人片无码天堂下载| 皇上H小妖精把腿张开| 亚洲精品国产A久久久久久| 激情内射亚洲一区二区三区| 亚洲国产精品无码久久久动漫| 和老师做H无码动漫| 亚洲精品自偷自拍无码| 久久精品噜噜噜成人AV| 野草乱码一二三四区别在哪| 老熟女露脸内射正在播放| 坐公交忘穿内裤被挺进老 | 波多野结衣初尝黑人巨大| 日本无遮挡吸乳视频| 国产超薄肉色丝袜视频| 午夜内射高潮视频| 加勒比AV一本大道香蕉大在线| 亚洲日韩精品欧美一区二区| 久久婷婷色综合老司机| 2021国产麻豆剧传媒网站| 欧美性爱群交视频| 成熟人妻AV无码专区| 我把护士日出水了视频90分钟| 国产又色又爽又刺激在线观看| 亚洲男同GV在线观看| 乱人伦中文无码视频| JAPANESE人妻中文字幕| 日韩 无码 偷拍 中文字幕| 国产成人无码AⅤ片在线观看| 亚洲AV无码成H人动漫网站| 精品亚洲国产成人AV| 中文午夜人妻无码看片| 人妻无码中文字幕| 国产精品成人免费视频网站| 亚洲AV中文无码乱人伦在线视色| 久久99精品久久久久子伦| 中文字幕精品无码| 日本XXXⅩ69XXXX护土| 国产精品夜间视频香蕉| 亚洲日本高清成人AⅤ片| 能让我流水水的一千字| 堕落女教师动漫全无修| 亚洲AV无码第一区二区三区| 久久人人妻人人爽人人爽| 扒开女人P添大荫蒂| 午夜131美女爱做视频| 久久久久久久精品成人热蜜桃| FREEFORNVIDEOS性| 未满十八岁可以去日本留学吗| 精品无码黑人又粗又大又长AV| 18禁无码无遮挡H动漫免费看| 日韩精品成熟妇人Av一区二区| 国产色母和进口色母区别| 在线播放国产不卡免费视频 | 老阿姨哔哩哔哩B站肉片入口6| 锕锕锕锕锕锕好污网站入口推特| 无码 一区二区三区 水蜜桃| 久久精品蜜芽亚洲国产AV| 锕锕锕锕锕锕锕好疼JK漫画| 性生生活大片又黄又| 免费看美女脱精光的网站| 俄罗斯老少配BBW| 亚洲精品无码AV天堂| 强行暴力肉体进入HDⅩXXX| 国产无遮挡无码视频免费软件 | 亚洲阿V天堂无码Z2018| 年轻漂亮的女邻居观看在线视频| 国产成人精欧美精品视频| 野花影视免费高清观看| 色老头BGMBGMBGM| 久久久久久精品免费免费4K| 德国FREE性VIDEO极品| 亚洲综合无码一区二区三区不卡|