Giter Club home page Giter Club logo

laravel_sample's Introduction

installation

cloneしたらプロジェクトディレクトリの中で以下のコマンドを上から順番に実行する

composer install
yarn
cp .env.example .env
php artisan key:generate
php artisan migrate:refresh --seed

だいたいの説明

.envファイルは.gitignoreなので.env.exampleからコピーして php artisan key:generateを実行する

ルーティング

routerでアクセス可能なURLを設定しないと全部404になる laravel内で作るならrouters/web.phpで設定する apiとして使うならrouters/api.phpで設定する。api.phpで設定したURLは全部 http://example.com/apiからはじまる

コントローラー

controllerはapp/Http/Controllers配下に設置。 ここらへんは他のフレームワークと同じ感じ

app/Http/Controllers/PostCodeController.php

モデル

modelの設置場所はデフォルトだとappの直下だけど、app/Modelみたいにディレクトリを掘ることが多い ※ディレクトリを掘るときはちゃんとnamespaceもいい感じにしないとダメ

app/Model/PostCodeModel.php

ビュー

viewファイルはresources/views配下に設置。 ファイル名末尾が.blade.phpじゃないとbladeが仕事してくれない

resources/views/Postcode/index.blade.php

LaravelのデフォルトでCSRF対策が有効なので は不要でも書いておくと良い(ajaxで通信したいときとかにcsrf_tokenを使う)

jsとcssはここにおいておけばおk public/js public/css

バリデーション

コントローラーの中でリクエストされたデータをバリデーションするのは美しくないのでリクエストを作って その中でやる。作るときはArtisan CLIコマンドで

php artisan make:request PostCodeRequest

を実行するとapp/Http/Requestsディレクトリが勝手にできて中でファイルが作られるのでそこに書いていく

※今回は作ってあるので上のコマンドそのまま打たなくて大丈夫 app/Http?Requests/PostCodeRequest.php

laravel_sample's People

Contributors

fyui001 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.