Laravel
PHP
學習紀錄
筆記
note
Laravel 筆記 目錄 架構 IOC DI 權限相關 Gate Artisan ARTISAN 命令全攻略 php artisan serve 行為追朔 HTTP Laravel 技能樹 Polymorphic Relations CRUD Delete Queue Fail Collection Eloquent hasManyThrough many to many 過程紀錄 狀況 參考資料 流程簡述 郵件驗證(Email Verification) Validation Middleware Observer Translation JWT Laravel Session 他人筆記 好用套件 Dependency Injection API該有的內容 152 Laravel Tips About Everything helpers 設定 好用helpers 8+版本 Collection Sanctum Guard Sail Laradock php-worker Get Real With Laravel Echo Sanctum API 對接 Auth 相關實用文章 Auth::id() 如何正確在 Laravel 撰寫 PHPUnit 單元測試(Unit Test) 品質檢測 Swagger API 文件 [教程] 在不同的 Laravel 应用中提供(服务端)和使用(客户端) OAuth2 认证 圖片處理 準備 需要的東西 來源二 實作內容 爬蟲 未完成 Socialite Laravel Socialite 簡單的代價 websocket 大佛十多年前的 ws 鐵人文章 chat 參考 CORS 講解的挺詳細的文章 Laravel ORM 分表查询 Laradock Elasticsearch 在Laravel项目中使用Elasticsearch 好用的片段程式碼 在 laravel 中取得 DB 的名稱 & 註解
public function test() { return $this->paginate(GameReport::get()) ->setPath(url()->current()); } public function paginate($items, $perPage = 15, $page = null, $options = []) { $page = $page ?: (Paginator::resolveCurrentPage() ?: 1); $items = $items instanceof Collection ? $items : Collection::make($items); return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options); }
<?php namespace App\Http\Controllers\Apis; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\Image; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; class UploadImageController extends Controller { /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validated = $request->validate([ 'image' => 'required|image', ]); // 將圖片轉換成 base64 $base64 = file_get_contents(data_get($validated, 'image')->path()); // 將 base64 轉換成 GD class $image = imagecreatefromstring($base64); // 取得原始寬高 $originWidth = imagesx($image); $originHeight = imagesy($image); // 在此控制 resize 的圖片要多寬 $width = 300; // 控制高度為原始比例 $height = round($width * $originHeight / $originWidth); // 使用 imagecreatetruecolor() 函數生成一個新的圖片。另一種寫法 $resizedImage = imagescale($image, $width) $resizedImage = imagecreatetruecolor($width, $height); // 使用 imagecopyresampled() 函數將原始圖片縮放到指定大小 imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $width, $height, $originWidth, $originHeight); // 生成新的圖片名稱 $name = uniqid() . '.png'; // 生成圖片的完整路徑 $fullPath = storage_path('app/public/' . $name); // 使用 imagepng() 函數將縮放後的圖片存儲到本地存儲空間中 imagepng($resizedImage, $fullPath); // 生成給前端使用的 url $imaPath = asset('storage/' . $name); return response()->json(['image' => $imaPath]); } }
<?php use App\Http\Controllers\NoteController; use App\Models\Image; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; use Symfony\Component\DomCrawler\Crawler; use Carbon\Carbon; Route::get('/test', function () { // 設定 PTT 的網址和板名 $url = 'https://www.ptt.cc/bbs/C_Chat/M.1536493373.A.1D6.html'; $board = 'C_Chat'; // 從 PTT 獲取文章內容 $response = Http::withOptions(['verify' => false]) ->get($url); $html = $response->body(); // 解析 HTML,並取得文章標題、作者、時間和內文 $crawler = new Crawler($html); return $crawler->text(); $title = $crawler->filter('.article-meta .article-meta-tag')->eq(2)->text(); $author = $crawler->filter('.article-meta .article-meta-value')->eq(0)->text(); $time_str = $crawler->filter('.article-meta .article-meta-value')->eq(3)->text(); $time = Carbon::parse(Str::after($time_str, ' ')); $content = $crawler->filter('#main-content')->text(); $content = Str::before($content, '--'); $result = [ 'board' => $board, 'title' => $title, 'author' => $author, 'time' => $time, 'content' => $content ]; return $result; // // 儲存文章到資料庫 // $post = new Post; // $post->board = $board; // $post->title = $title; // $post->author = $author; // $post->published_at = $time; // $post->content = $content; // $post->save(); });
$temp = []; $tableName = 'p30_entertainment_wallet_stored'; $columnComments = DB::select("SELECT COLUMN_NAME, COLUMN_COMMENT FROM information_schema.COLUMNS WHERE TABLE_NAME = ?", [$tableName]); foreach ($columnComments as $column) { $columnName = $column->COLUMN_NAME; $columnComment = $column->COLUMN_COMMENT; $temp[] = [ $columnName, $columnComment ]; } return $temp;
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up