gmnon.cn-疯狂蹂躏欧美一区二区精品,欧美精品久久久久a,高清在线视频日韩欧美,日韩免费av一区二区

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

新鮮出爐的Laravel 速查表不要錯(cuò)過(guò)!

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


Laravel 速查表

項(xiàng)目命令

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

公共指令

// 數(shù)據(jù)庫(kù)遷移 $ php artisan migrate  // 數(shù)據(jù)填充 $ php artisan db:seed  // 創(chuàng)建數(shù)據(jù)表遷移文件 $ php artisan make:migration create_products_table  // 生成模型選項(xiàng):  // -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',];  // 一對(duì)多關(guān)系 (一條帖子對(duì)應(yīng)多條評(píng)論) public function comments()  {     return $this->hasMany(Comment:class);  }  // 一對(duì)多關(guān)系 (多條評(píng)論在一條帖子下)  public function post()  {                                 return $this->belongTo(Post::class);  }  // 一對(duì)一關(guān)系 (作者和個(gè)人簡(jiǎn)介) public function profile()  {     return $this->hasOne(Profile::class);  }  // 一對(duì)一關(guān)系 (個(gè)人簡(jiǎn)介和作者)  public function author()  {                                 return $this->belongTo(Author::class);  }  // 多對(duì)多關(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 選項(xiàng) : https://github.com/fzaninotto/Faker

Seed

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

運(yùn)行 Seeders

$ php artisan db:seed // 或者 migration 時(shí)執(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ù)主鍵查詢(xún)一條記錄 $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']);  // 僅針對(duì)特定 HTTP 動(dòng)詞的路由 Route::match(['get', 'post'], '/', function () {     // });  // 響應(yīng)所有 HTTP 請(qǐng)求的路由 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' ]);  // 使用路由名稱(chēng)生成 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  // 獲取或保存(鍵,存活時(shí)間,值) $users = Cache::remember('users', now()->addMinutes(5), function () {     return DB::table('users')->get(); });

控制器

// 設(shè)置校驗(yàn)規(guī)則 protected $rules = [     'title' => 'required|unique:posts|max:255',     'name' => 'required|min:6',     'email' => 'required|email',     'publish_at' => 'nullable|date', ];  // 校驗(yàn) $validatedData = $request->validate($rules)  // 顯示 404 錯(cuò)誤頁(yè) 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)前用戶(hù) --> {{ Auth::user()->name }}  <!-- Validations 驗(yàn)證錯(cuò)誤 --> @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">  <!-- 上一次請(qǐng)求數(shù)據(jù)填充表單 --> {{ old('name') }}

不使用模型訪問(wèn)數(shù)據(jù)庫(kù)

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ù)

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

閃存 和 Session

// 閃存(只有下一個(gè)請(qǐng)求) $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 方式請(qǐng)求 $response = Http::get('www.thecat.com') $data = $response->json()  // Http get 帶參方式請(qǐng)求 $res = Http::get('www.thecat.com', ['param1', 'param2'])  // Http post 帶請(qǐng)求體方式請(qǐng)求 $res = Http::post('http://test.com', ['name' => 'Steve','role' => 'Admin']);  // 帶令牌認(rèn)證方式請(qǐng)求 $res = Http::withToken('123456789')->post('http://the.com', ['name' => 'Steve']);  // 帶請(qǐng)求頭方式發(fā)起請(qǐng)求 $res = Http::withHeaders(['type'=>'json'])->post('http://the.com', ['name' => 'Steve']);

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

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

從 github 安裝新項(xiàng)目

$ 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 端點(diǎn))

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 控制器 (最佳實(shí)踐是將您的 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)證

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

贊(0)
分享到: 更多 (0)
網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)
gmnon.cn-疯狂蹂躏欧美一区二区精品,欧美精品久久久久a,高清在线视频日韩欧美,日韩免费av一区二区
狠狠噜天天噜日日噜| 日韩在线视频在线| 在线观看岛国av| 亚洲av无日韩毛片久久| 亚洲一区二区三区观看| 免费看av软件| 日本久久久精品视频| 国产成人在线综合| 国产亚洲黄色片| 亚洲综合在线网站| aa在线观看视频| 国产3p在线播放| 人妻夜夜添夜夜无码av| 日本成人中文字幕在线| 免费网站永久免费观看| www.xxx亚洲| 国产精品69久久久| 国产又粗又大又爽的视频| 丝袜老师办公室里做好紧好爽| 日日噜噜夜夜狠狠| 国产欧美久久久久| 午夜激情影院在线观看| 无人在线观看的免费高清视频 | 中文字幕12页| 日本激情视频在线播放| cao在线观看| 欧美 丝袜 自拍 制服 另类| 可以免费看的黄色网址| 国产精品50p| 妓院一钑片免看黄大片| 成年人视频在线免费| 激情综合在线观看| 国产 福利 在线| 99久久久无码国产精品6| 女人扒开屁股爽桶30分钟| 久久成人免费观看| 三年中国国语在线播放免费| 欧美性猛交xxx乱久交| 一起操在线视频| 久久最新免费视频| 91网站在线观看免费| 男人天堂1024| www.51色.com| 免费无遮挡无码永久视频| 欧美激情成人网| 男人的天堂avav| www.日日操| 99精品人妻少妇一区二区| 91福利免费观看| 97在线免费公开视频| 欧美国产日韩在线视频| 免费在线观看日韩视频| 影音先锋成人资源网站| 色一情一乱一伦一区二区三区日本| 亚洲77777| 亚洲成人av免费看| 欧美人与动牲交xxxxbbbb| 宅男噜噜噜66国产免费观看| 精品免费久久久久久久| www.黄色网址.com| 日本人69视频| 九九热99视频| 亚洲精品成人在线播放| 国产一区二区视频免费在线观看| 在线观看污视频| 黄色小视频大全| 青青草原网站在线观看| 国产精品h视频| 成年在线观看视频| 国产精品无码人妻一区二区在线| 四虎影院一区二区| 男插女免费视频| 国内精品在线观看视频| 久久国产亚洲精品无码| 乱妇乱女熟妇熟女网站| aa免费在线观看| mm131亚洲精品| 日本一级黄视频| 激情五月开心婷婷| 亚洲污视频在线观看| 欧美 亚洲 视频| 日av中文字幕| 亚洲国产精品影视| 日本久久久精品视频| 第一区免费在线观看| 99久久国产综合精品五月天喷水| 狠狠干 狠狠操| 肉大捧一出免费观看网站在线播放| 国产xxxx振车| 成人免费在线观看视频网站| 欧美一级黄色录像片| 精品999在线| 黄色www网站| 国产a级黄色大片| 亚洲一二三av| www.超碰97.com| 九一精品在线观看| 美女av免费在线观看| 无颜之月在线看| 麻豆传媒网站在线观看| 五月婷婷六月丁香激情| 97国产精东麻豆人妻电影| 三级在线免费观看| 亚洲日本黄色片| 国产视频1区2区3区| 亚洲精品久久久久久宅男| www.天天射.com| 污视频网站观看| 超碰在线免费观看97| 婷婷激情综合五月天| 中文字幕一区二区三区四区五区人| 无遮挡又爽又刺激的视频| 成人羞羞国产免费网站| 狠狠97人人婷婷五月| 男女激情无遮挡| 日韩av卡一卡二| 天天操天天干天天玩| 51xx午夜影福利| 国产精品无码人妻一区二区在线| 人人妻人人做人人爽| www.激情小说.com| www.色.com| 爱情岛论坛vip永久入口| 992kp免费看片| 亚洲中文字幕无码专区| 黄大色黄女片18第一次| 免费一级特黄毛片| 日韩av在线中文| 日本精品www| 男女激烈动态图| 亚洲天堂av一区二区三区| 精品中文字幕av| 成人国产在线看| 污污的视频免费观看| 国产1区2区在线| 人妻少妇精品久久| www.久久com| 亚洲高清在线不卡| 亚洲另类第一页| 最近中文字幕一区二区| 日本不卡在线观看视频| 美女日批免费视频| 黄色激情在线视频| 国产精品www在线观看| 日本精品福利视频| 黄色a级片免费看| 成人一级生活片| 人人妻人人澡人人爽欧美一区双| 97免费视频观看| 桥本有菜av在线| 成人午夜免费剧场| 黄色一级视频播放| 天堂8在线天堂资源bt| 8x8ⅹ国产精品一区二区二区| 国产在线观看中文字幕| 日本高清免费观看| 国产精品8888| 妺妺窝人体色777777| 一二三四视频社区在线| 国产原创中文在线观看| 亚洲一区二区蜜桃| 手机看片福利日韩| 亚洲一级免费观看| 色哺乳xxxxhd奶水米仓惠香| 国产欧美综合一区| www.com毛片| 可以免费看的黄色网址| 浮妇高潮喷白浆视频| eeuss中文| 99热手机在线| 妺妺窝人体色www在线小说| 国产三级国产精品国产专区50| 精品综合久久久久| 中文字幕av不卡在线| 一二三在线视频| 免费无码国产v片在线观看| 国产免费人做人爱午夜视频| 中文字幕资源在线观看| 91九色丨porny丨国产jk| 福利在线一区二区三区| 欧美国产亚洲一区| 桥本有菜av在线| 性刺激的欧美三级视频| 免费观看国产精品视频| 热这里只有精品| 波多野结衣激情| 一级黄色高清视频| 亚洲精品20p| 国产九九九视频| 欧美人与动牲交xxxxbbbb| 一道本在线免费视频| 日本黄色播放器| 免费无码不卡视频在线观看| 欧美老熟妇喷水| 亚洲综合伊人久久| 亚洲理论电影在线观看| 中文字幕亚洲乱码| 欧美成人手机在线视频| 麻豆一区二区三区在线观看| 成人在线免费观看视频网站|