Laravel 回傳 json的亂碼解決方式

在Laravel中我們要產出json格式的話,一般只要
[php]
Route::get(‘json’, function () {
$users = DB::table(‘users’)->get();
return Response::json($users);
}
[/php]
但是遇到中文時,會出現有亂碼的問題,解決很簡單
[php]
Route::get(‘json’, function () {
$headers = array(‘Content-Type’ => ‘application/json; charset=utf-8’);
$users = DB::table(‘users’)->get();
return Response::json($users, 200, $headers, JSON_UNESCAPED_UNICODE);
});
[/php]

Laravel 5.3 連接 SQL Server

一、下載 https://github.com/superlevin/xamppforlaravel

二、config/database.ph的connections增加
[php]
‘sqlsrv’ => [
‘driver’ => ‘sqlsrv’,
‘host’ => env(‘DB_HOST’, ‘localhost’),
‘database’ => env(‘DB_DATABASE’, ‘dbname’),
‘username’ => env(‘DB_USERNAME’, ‘dbuser’),
‘password’ => env(‘DB_PASSWORD’, ‘dbpassword’),
‘charset’ => ‘utf8’,
‘prefix’ => ”,
],
[/php]
三、.env修改連線
[php]
DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_PORT=1433
DB_DATABASE=dbname
DB_USERNAME=dbuser
DB_PASSWORD=dbpassword
[/php]
四、測試是否可以產生
routes/web.php
[php]
Route::get(‘/’, function () {
var_dump( DB::table(‘tablename’)->first() );
});
[/php]

Delphi 10 Berlin 在tabitem加上數字

tabbarcustom
[pascal]
interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl, FMX.Controls.Presentation, FMX.Edit,
FMX.EditBox, FMX.SpinBox, FMX.StdCtrls, FMX.Layouts, FMX.ListBox,
FMX.NumberBox;

type
TForm16 = class(TForm)
TabItem1: TTabItem;
TabItem2: TTabItem;
BadgeItem: TTabItem;
SpinBox1: TSpinBox;
ToolBar1: TToolBar;
Switch1: TSwitch;
ListBox1: TListBox;
ListBoxItem1: TListBoxItem;
ToolLabel: TLabel;
TabControl1: TTabControl;
procedure BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
procedure SpinBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Switch1Switch(Sender: TObject);
procedure StepperUpClick(Sender: TObject);
private
FBadge: Integer;
FShowBadge: Boolean;
procedure SetBadge(const Value: Integer);
procedure SetShowBadge(const Value: Boolean);
{ Private declarations }
public
{ Public declarations }
property Badge: Integer read FBadge write SetBadge;
property ShowBadge: Boolean read FShowBadge write SetShowBadge;
end;

var
Form16: TForm16;

implementation

{$R *.fmx}
{$R *.iPhone55in.fmx IOS}

procedure DrawBadge(Canvas: TCanvas; const ARect: TRectF; const Text: string;
const Color: TAlphaColor = TAlphaColorRec.Red);
const
Padding = 2;
HorzTextMargin = 6;
VertTextMargin = 4;
var
R: TRectF;
TextSize: TSizeF;
Brush: TBrush;
BadgeRadius: Single;
begin
Canvas.Font.Size := 12;
// Measure text width
TextSize := TSizeF.Create(Canvas.TextWidth(Text), Canvas.TextHeight(Text));
// Calculate badge rect
R := TRectF.Create(0, 0, HorzTextMargin * 2 + TextSize.Width, VertTextMargin * 2 + TextSize.Height);
if R.Width < R.Height then
R.Width := R.Height;
// Position rect
R := TRectF.Create(ARect.Right – R.Width, ARect.Top, ARect.Right, ARect.Top + R.Height);
R.Offset(-Padding, Padding);
// Draw badge
BadgeRadius := R.Height / 2;
Brush := TBrush.Create(TBrushKind.Solid, Color);
try
Canvas.FillRect(R, BadgeRadius, BadgeRadius, AllCorners, 1, Brush);
finally
Brush.Free;
end;
// Draw text
Canvas.Fill.Color := TAlphaColorRec.White;
Canvas.FillText(R, Text, False, 1, [], TTextAlign.Center, TTextAlign.Center);
end;

procedure TForm16.BadgeItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
begin
if ShowBadge then
DrawBadge(Canvas, ARect, FBadge.ToString);
end;

procedure TForm16.FormCreate(Sender: TObject);
begin
FBadge := 1;
end;

procedure TForm16.SetBadge(const Value: Integer);
begin
if FBadge Value then
begin
FBadge := Value;
BadgeItem.Repaint;
end;
end;

procedure TForm16.SetShowBadge(const Value: Boolean);
begin
if FShowBadge Value then
begin
FShowBadge := Value;
BadgeItem.Repaint;
end;
end;

procedure TForm16.SpinBox1Change(Sender: TObject);
begin
Badge := Trunc(SpinBox1.Value);
end;

procedure TForm16.StepperUpClick(Sender: TObject);
begin
Badge := Trunc(SpinBox1.Value);
end;

procedure TForm16.Switch1Switch(Sender: TObject);
begin
ShowBadge := Switch1.IsChecked;
end;

end.
[/pascal]
原始資料:https://community.embarcadero.com/blogs?view=entry&id=9074

Laravel 5.3 Artisan 自動建立CRUD的Controller

在5.2之前,是使用以上指令產生有resource(CRUD函數的controller)
[php]
php artisan make:controller MyNameController
[/php]
然後
[php]
php artisan make:controller MyNameController –plain
[/php]
在5.3,改為要加上 –resource才有
[php]
php artisan make:controller MyNameController –resource
[/php]

PHP教學 – 這學期教的laravel 5.3課程內容

上個學期是教Codeigniter,這學期開始也要進入Laravel了!內容大致如下面~
Laravel介紹
MVC架構解說
Git版本控制介紹與安裝
Composer套件管理

Laravel安裝

Package安裝及使用
Route路由
Migrations/Seed 資料的遷移與填充

Eloquent ORM資料庫互動

View與Blade模板引擎
Controller實戰

CRUD 綜合運用

表單與驗證技巧
會員認證
網站安全性