2020年10月28日水曜日

git remote

remote(github)すでにある、localでもgit initで作った。remoteとlocalを連結させるため
git remote add origin https://github.com/xxx/yyy.git

localですでにgitあり、remote(gitlab)まだない、local gitをremoteで反映させる
git remote add origin https://アカウント名@gitlab.com/アカウント名/プロジェクト名.git

削除
git remote rm origin // 関連性を削除
git remote remove origin // remote repository削除

2020年8月24日月曜日

laravel projectにてhtpasswd でbase認証をかける

1)base認証用password fileを作成

mkdir /etc/htpasswd (必要に応じて)

htpasswd -c /etc/htpasswd/.htpasswd username(コマンドを実行すると、PW入力を要求される)


2)/var/www/html/site/public/.htaccess を変更

一番上に、以下を追加


AuthType Basic

AuthName "Authentication Required"

AuthUserFile "/etc/htpasswd/.htpasswd"

Require valid-user

サクラVPSにSSLを導入

 1)certbotインストール

yum install certbot python2-certbot-apache


2)apache confファイルの最後に下記VirtualHost追加


NameVirtualHost *:80


<VirtualHost *:80>

ServerAdmin root@xxx.com

DocumentRoot /var/www/html/site/public

ServerName xxx.com


3)certbotコマンドを実行して証明書をインストール

certbot --apache -d xxx.com

※実施中、httpをhttpsへredirectするか聞いてくる際、redirectするようにします。


初期ドメイン→独自ドメイン リダイレクト

以下の内容をapache confファイルに追加

<VirtualHost *:80>

ServerAdmin root@xxx.com

DocumentRoot /var/www/html/site/public

ServerName os1-234-56789.vs.sakura.ne.jp

RewriteEngine on

RewriteCond %{SERVER_NAME} =os1-234-56789.vs.sakura.ne.jp

RewriteRule ^ https://xxx.com%{REQUEST_URI} [END,NE,R=permanent]


4)証明書を更新

certbot renew

2019年7月5日金曜日

ssh転送でremote mysqlをlocal開発に利用


ssh -f -N -L 13306:localhost:3306 username@10.10.10.10 -p 22

2019年6月3日月曜日

laravel type hintでobjとれない件

以下のrouting定義がある。
Route::resource('tokus', 'TokuController')

controllerで下記のtype hintがあるが、dd($toku)であるはずのobjがとれない。
public function show(Toku $toku)
    {
        return view('tokus.show', compact('toku'));
    }

route:listで確認したところ、show actionのURIは、tokes/{tokes}になっている。
type hintの引数は{tokes}と一致しないといけないため、public function show(Toku $tokus)に変更したら解決できた。それが嫌なら、引数を指定できる。

Route::resource('tokus', 'TokuController')->parameters([
    'tokus' => 'toku'
]);

参考:https://laracasts.com/discuss/channels/laravel/controller-method-with-type-hinting-give-empty-eloquent-object

2019年5月30日木曜日

laravel middleware

Controllers also allow you to register middleware using a Closure. This provides a convenient way to define a middleware for a single controller without defining an entire middleware class:

$this->middleware(function ($request, $next) {
    // ...

    return $next($request);
});

resource controller

php artisan make:controller PhotoController --resource
Route::resource('photos', 'PhotoController');
Route::resources([
    'photos' => 'PhotoController',
    'posts' => 'PostController'
]);

Partial Resource Routes

Route::resource('photos', 'PhotoController')->only([
    'index', 'show'
]);

Route::resource('photos', 'PhotoController')->except([
    'create', 'store', 'update', 'destroy'
]);

Route::apiResources([
    'photos' => 'PhotoController',
    'posts' => 'PostController'
]);

If you need to add additional routes to a resource controller beyond the default set of resource routes, you should define those routes before your call to Route::resource

Route::get('photos/popular', 'PhotoController@method');
Route::resource('photos', 'PhotoController');

You may even restrict the middleware to only certain methods on the controller class:

public function __construct()
    {
        $this->middleware('auth');

        $this->middleware('log')->only('index');

        $this->middleware('subscribed')->except('store');
    }

// 一覧
GET /projects (index)

// 新規ページ
GET /projects/create (create)

// 保存
POST /projects (store)

// show project
GET /projects/{id}

// 編集ページ
GET /projects/{id}/edit (edit)

// 更新
PATCH /projects/{id} (update)

// 削除
DELETE /projects/{id} (destroy)

Dependency Injection & Controllers

Injectionの場所は2つある
1)Constructor Injection
class UserController extends Controller
{
    /**
     * The user repository instance.
     */
    protected $users;

    /**
     * Create a new controller instance.
     *
     * @param  UserRepository  $users
     * @return void
     */
    public function __construct(UserRepository $users)
    {
        $this->users = $users;
    }
}

2)Method Injection
class UserController extends Controller
{
    /**
     * Store a new user.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        $name = $request->name;

        //
    }
}