亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

? PHP ????? Laravel PHP?? laravel ?????? ??? ??(???)

PHP?? laravel ?????? ??? ??(???)

Jul 16, 2020 am 11:59 AM
laravel

PHP?? laravel ?????? ??? ??(???)

關(guān)于laravel的介紹就不講了,總之laravel是款比較強大的框架,它是國外框架所以在安裝的上面可能比較麻煩。

laravel的安裝

首先安裝laravel之前要安裝composer,如果是linux系統(tǒng)即可直接下載安裝,下載完后不能安裝記得修改下文件權(quán)限用命令chmod,這邊主要講下window下如何使用composer這個工具。?

首先百度搜索中國composer鏡像,就可以找到composer config -g repositories.packagist composer?http://packagist.phpcomposer.com這條命令,運行cmd在命令行運行上面的命令,就可以下載composer工具,

下載成功后可以看到composer文件底下有個composer.json文件這是一個配置文件,打開配置文件寫明php版本信息和要下載的laravel信息,格式如下:

  {
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-update-cmd": [
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "repositories": [
        {"type": "composer", "url": "http://packagist.phpcomposer.com"},
        {"packagist": false}
    ]
}```

配置好之后輸入composer install 進行安裝laravel,這邊要比較注意的是安裝目錄的路徑問題,如果你想安裝在d盤底下就在把命令行切到d目錄底下進行安裝(在此操作之前要配置好環(huán)境變量)。

laravel的目錄結(jié)構(gòu)介紹

安裝完的第一次肯定是要想怎么去運行它,很簡單,直接進入public文件就可以打開一個開始頁面,如果在本地的話那就是localhost/laravelproject/public,就可以運行。

接下來介紹下laravel目錄結(jié)構(gòu),首先介紹下public的index.php文件 里面主要是加載了開始文件然后才能成功運行l(wèi)aravel,具體的兩個文件你可以在根目錄下bootstrap文件夾中找到?,F(xiàn)在看下app中的結(jié)構(gòu):

PHP?? laravel ?????? ??? ??(???)
view中主要放的是視圖文件(創(chuàng)建文件時要用到blade模板,比如創(chuàng)建test.blade.php,laravel中是結(jié)合blade模板引擎來調(diào)用視圖模板)

controller放的是控制器(手動創(chuàng)建時記得要用composer 命令進行更新)

config中主要是配置文件(比如配置數(shù)據(jù)庫時要用到database.php文件)

models主要是放模型(也就是數(shù)據(jù)庫的表)

routes則是路由配置,

filters則是過濾器。

laravel是怎么運行的

剛學(xué)習(xí)時肯定是要先嘗試下如何運行這個laravel,首先手動創(chuàng)建一個controller,文件命名為TestController.php,然打開命令行進入項目的根目錄下 執(zhí)行 composer dumpautoload,里面內(nèi)容可以模仿homeController.php。

然后編輯routes.php文件,將原來的Route::GET(‘/’,function()…);修改為Route::Get(‘/’,’TestController@showWelcome’); 然后運行也會跳到laravel歡迎界面。

如果Route::Get(‘test’,’TestController@showWelcome’);則在網(wǎng)站根目錄下后面直接增加test就可以訪問了,到了這里應(yīng)該明白了怎么到Controller,Controller怎么到View了。

laravel數(shù)據(jù)庫配置

這邊用到的是mysql,進行了簡單的配置

'mysql' => array(
'driver'    => 'mysql',
'host'      => 'localhost',
'database'  => 'oss',
'username'  => 'root',
'password'  => '',
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',
)

laravel的數(shù)據(jù)庫使用

數(shù)據(jù)表比較多時且數(shù)據(jù)表的前綴不一樣,則可以先配置模型model,在models文件夾中建立一個文件要與表名一樣的php文件,內(nèi)容如下:
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
    use UserTrait, RemindableTrait;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = &#39;users&#39;;
    /**
     * The attributes excluded from the model&#39;s JSON form.
     *
     * @var array
     */
    protected $hidden = array(&#39;password&#39;, &#39;remember_token&#39;);
}

即可以直接使用 User ::all() 查詢所有結(jié)果 ,User::find(2)查詢一個,Post::findOrFail(2)

如果沒找到就會返回錯誤,Post::save()、Post::where()->find()、Post::add()、Post::delete()

數(shù)據(jù)庫的簡便操作:

DB::table(‘tablename’)->insert([
        插入多個時要再加一個數(shù)組
        [&#39;title&#39;=>&#39;title&#39;,&#39;name&#39;=>&#39;name&#39;]
        [&#39;title&#39;=>&#39;title&#39;]
        [&#39;title&#39;=>&#39;title&#39;]
        ])
        插入時要想得到ID
        DB::table(&#39;tablename&#39;)->insertGetId([&#39;title&#39;=>&#39;titles&#39;])
        更新數(shù)據(jù)要有ID
        DB::table(&#39;tablename&#39;)->where(&#39;id&#39;,1)->update([&#39;title&#39;=>&#39;titles&#39;])
        刪除數(shù)據(jù)
        DB::table(&#39;tablename&#39;)->where(&#39;id&#39;,1)->delete();
        查詢數(shù)據(jù)
        DB::table(&#39;tablename&#39;)->get();  得到全部的值
        DB::table(&#39;tablename&#39;)->get([&#39;title&#39;]); 只查詢title的值
        DB::table(&#39;tablename&#39;)->first();  只拿第一個
        DB::table(&#39;tablename&#39;)->orderBy(&#39;id&#39;,&#39;desc&#39;)->first(); 根據(jù)id排序
        DB::table(&#39;tablename&#39;)->where(&#39;id&#39;,&#39;!=&#39;,2)->get(); 不等于2
        DB::table(&#39;tablename&#39;)->where(&#39;id&#39;,&#39;!=&#39;,2)->where(&#39;id&#39;,&#39;>&#39;,5)->get(); 可以使用多個where
        DB::table(&#39;tablename&#39;)->where(&#39;id&#39;,&#39;!=&#39;,2)->OrWhere(&#39;id&#39;,&#39;>&#39;,5)->get(); 或者
        DB::table(&#39;tablename&#39;)->whereBetween(&#39;id&#39;,[2,5])->get();  閉包之間
        DB::table(&#39;tablename&#39;)->whereIn(&#39;id&#39;,[2,5,9])->get();
        DB::table(&#39;tablename&#39;)->whereNotIn(&#39;id&#39;,[2,5,9])->get();
        DB::table(&#39;tablename&#39;)->whereNull(&#39;id&#39;)->get();  為空的話就可以查詢出來
        DB::table(&#39;tablename&#39;)->take(3)->get();  只查詢3個
        DB::table(&#39;tablename&#39;)->limit(3)->get();  只查詢3個
        DB::table(&#39;tablename&#39;)->skip(2)->take(3)->get();  只查詢3個跳過第二個
        DB::table(&#39;tablename&#39;)->where(&#39;id&#39;,&#39;!=&#39;,2)->pluck(&#39;title&#39;); 只返回它的title
        DB::table(&#39;tablename&#39;)->count();  有多少條記錄
        DB::table(&#39;tablename&#39;)->max(&#39;id&#39;);
        DB::table(&#39;tablename&#39;)->min(&#39;id&#39;);
        DB::table(&#39;tablename&#39;)->avg(&#39;id&#39;);
        DB::table(&#39;tablename&#39;)->sum(&#39;id&#39;);

多表關(guān)聯(lián)

在Post中定義

public function comment(){ return $this->hasMany(&#39;Comment&#39;,&#39;post_id&#39;) }
 正向關(guān)聯(lián)   一對多   一對一是hasOne

在Comment中定義

public function post(){ return $this->belongsTo(&#39;Post&#39;,&#39;post_id&#39;) }
  反向關(guān)聯(lián)

取得關(guān)聯(lián)值

    Post::find(2)->comment  就可以得到Comment這張表的內(nèi)容   //這樣查詢一個是可以的  查詢多個就要設(shè)置預(yù)載入
            查詢多個
                Post::with(&#39;comment&#39;)->get();
                Post::with([&#39;comment&#39;=>function($query){$query->where(&#39;id&#39;,&#39;>&#39;,2)}])->get();  加條件

感謝大家的閱讀,希望大家有所收益。

本文轉(zhuǎn)自:https://blog.csdn.net/Happy_CSDN/article/details/49363219

推薦教程:《php教程

? ??? PHP?? laravel ?????? ??? ??(???)? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1597
29
PHP ????
1488
72
NYT ?? ??? ??
131
836
???
PHP ???? ?? ??? ???? ?? PHP ?? ?? ?? ??? ?? ?? PHP ???? ?? ??? ???? ?? PHP ?? ?? ?? ??? ?? ?? Jul 25, 2025 pm 08:33 PM

PHP?? ?? ??? ???? ? ?? ?? ??? ????. 1. php.ini? ?? ??? ??; 2. ? ?? (? : Apache? Setenv ?? nginx? FastCGI_Param)? ??????. 3. PHP ?????? putenv () ??? ??????. ? ??? Php.ini? ????? ??? ???? ??? ???? ? ?? ??? ?? ???? ????? ???? Putenv ()? ?? ??? ?????. ?? ???? ?? ?? (? : php.ini ?? ? ?? ??)? ???? ????. ?? ?? ??? ??? ?? ??? ????? ???? ?? ????.

PHP ????? ?? ??? ??? ??? ?????? PHP ??? ????? ?? ? CI ?? ?? PHP ????? ?? ??? ??? ??? ?????? PHP ??? ????? ?? ? CI ?? ?? Jul 25, 2025 pm 08:54 PM

PHP ????? ?? ??? ??? ? ??? ??? CI (Continuous Integration) ????? ???? ? ????. 1. DockerFile? ???? ?? ???, ?? ??, ??? ?? ? ?? ??? ???? PHP ??? ?????. 2. Gitlabci? ?? CI/CD ??? ???? .gitlab-ci.yml ??? ?? ??, ??? ? ?? ??? ???? ?? ??, ??? ? ??? ?????. 3. PHPUNIT? ?? ??? ??? ??? ???? ?? ?? ? ???? ???? ????????. 4. Kubernetes? ?? ?? ?? ??? ???? ?? .yaml ??? ?? ?? ??? ?????. 5. Dockerfile ??? ? ??? ??? ??????

Laravel? ?? ???? ?????? Laravel? ?? ???? ?????? Jul 27, 2025 am 03:54 AM

Laravel? ?? ??? ?? ?? ??? ?? ?? ??? ???? ??? ??????. ?? ???? ?? ??? ????? ? ???? I/O ?? ? ?? ?? ??? ???? ???? ??? ?? ? ????. 1. ?? ????? ?? ? ? ???????? ??? ????? ?? ???? ??????. 2. ??? ? ??? ?? ? ? PhPartisAnconfig? ?? ???????. 3. ?? ??? ??? ??? ???? ?? ?? ?? ???? ???? ????. 4. ?? ?? ??? ???? ?? ??? ??? .env ??? ???? ?? ???????.

PHP PHP ??? ?? ?? ? ???? AI ??? ?? ???? ???? ?? PHP PHP ??? ?? ?? ? ???? AI ??? ?? ???? ???? ?? Jul 25, 2025 pm 05:54 PM

??? PHP ??? ??? ??? ?? ???? ??? ?? ????? ???????. Laravel? ?? ??? ???? ??? ? ? ???? ??? ??? ???? ?????? ?? ? ?? ?? ???? ?????. Symfony? ? ???? ??? ???? ?????. Codeigniter? ??? ??? ?? ??? ?? ??? ?? ????? ?????. 2. AI ??? ???? ????? ??? ??? ??, ???? ?? ?? (? : ???, ??, F1 ?), ??? ? ?? ?? ? ?? ??? ?? ???? ?? ??? ???? ???? ?? ??? ? ?? ???? ?? ?? ??? ????? ?? ???? ????? ?????? ??? ????? ???????. 3. ??? ?? ?? ????? ?? ??? ?????. AES? ?? ??? ???? ????? ?????.

PHP? ?? ??? ?? ??? ?? ?? PHP ?? ?? ???? ???? ?? PHP? ?? ??? ?? ??? ?? ?? PHP ?? ?? ???? ???? ?? Jul 25, 2025 pm 06:30 PM

PHP ??? ?? ???? ????? ??? ??, ??? ??, ?? ? ?? ?? ???? ???????. ??, ??? ?? ???? ???? JWT? ???? ??? ??? ??????. ??, ??? ?? ????? ? ?????? ??? ???? ?? ???? ?????. ??, Alipay ?? WeChat ??? ???? ???? ??? ?????. ??, ?? ?? ??? ?? ??? ??? ??? ?????. Laravel ??? ??? ???? ?? ???? ?????, ?? ?? ? ??? ??? ???? ??? ??? ????, ??? ????? ??, ??????, ?? ? ?? ??? ?????? ??? ??? ??????? ??? ? ??? ???????.

PHP ?? ??? ?? ?? ?? ?? PHP ?? ?? ? ?? ?? PHP ?? ??? ?? ?? ?? ?? PHP ?? ?? ? ?? ?? Jul 25, 2025 pm 06:51 PM

??? ?? ??? PHP ???? ?? ?? ??? ???? ?? ???????. RBAC (Role-Based Access Control) ??? ?? ???, ?? ? ??? ???? ??? ?? ?? ? ??? ?????. ?? ???? ??? ?????. 1. ???, ?? ? ??? ? ???? user_roles ? role_permissions? 3 ?? ?? ???; 2. $ user-> can ( 'edit_post')? ?? ???? ?? ?? ??? ?????. 3. ??? ???? ??? ??????. 4. ?? ??? ???? ?? ?? ?? ? ??? ? ???? ???? ?? ??? ? ?? ??? ?????. 5. ??? ??? ?? ?? ???? ?? ???? "??"? ??????.

PHP? ???? AI? ???? ??? ??? PHP ??? ??? ?? ??? ?????. PHP? ???? AI? ???? ??? ??? PHP ??? ??? ?? ??? ?????. Jul 25, 2025 pm 06:15 PM

??? ??? ??? ?? AI? ??? PHP? ?? ????? PHP? ??? "???"?????, ?? ???? ????? ???? ??? ? ??, ASYNCHRONOUS ??? ?? AI ??? (? : Google CloudVideoAi ?)? ??????? ????. 2. PHP? JSON ??? ?? ????, ??, ??, ??, ?? ? ?? ??? ???? ??? ??? ???? ??????? ?????. 3. ??? PHP? ??? ? ???? ???? ?? PHP ?????? ????? ????? ???? ? ??? AI ??? ???? ???? ????. 4. ???? ???? ??? ?? ?? (?? ?? ? URL??? ???? ????? ?? ??), ??? ?? (??? ??? ??), ?? ?? (??? ??, ?? ????) ? ?? ??? (?? ???)? ?????. 5. ??? ??? ????? ?? ?????

Laravel Eloquent Scopes? ??????. Laravel Eloquent Scopes? ??????. Jul 26, 2025 am 07:22 AM

Laravel? eloquentscopes? ?? ??? ??? ??? ?????? ?? ?? ??? ????? ?????. 1. ?? ??? ???? ???? ???? ???? Post :: published (); 2. ??? ??? ?? ??? ???? ???? ?? ??? ?? ?? ?? ??? ???? ???? ??? ?????? ??? ???? ???????. 3. ????? ?? ?? ?? ??? ??? ?? ?? ??? ?? ? ? ??? ?? ? ? ?? ?? ??? ?????. 4. ?? ??? ? ??? ?? ???? ? ??? ? ?? ??, ?? ??, ?? ???? ? ?? ?????????.

See all articles