透過CMD新增File

用命令提示字元超快

基本的新增

以下是不需要任何設定就可以直接新增檔案的方式

先叫出命令提示字元,直接來到你的專案的資料夾,按下ctrl+shift然後右鍵點專案的資料夾,就會多出幾個選項,選擇其中一個"在此處開啟命令視窗"然後key入以下的程式碼即可:

php artisan make:controller 名稱 --resource

然後把C換成M就可以長好你要的檔案了,都會幫你歸類清楚喔,超實用。

特殊的新增

以下是需要做相關的設定才可以使用cmd新增

將以下的程式碼新增到/App/Repositories命名為BaseRepository.php

<?php
namespace App\Repositories;
use Illuminate\Database\Eloquent\Model;
class BaseRepository
{
    /**
     * The Model name.
     *
     * @var \Illuminate\Database\Eloquent\Model;
     */
    protected $model;
    /**
     * Paginate the given query.
     *
     * @param The number of models to return for pagination $n integer
     *
     * @return mixed
     */
    public function getPaginate($n)
    {
        return $this->model->paginate($n);
    }
    /**
     * Create a new model and return the instance.
     *
     * @param array $inputs
     *
     * @return Model instance
     */
    public function store(array $inputs)
    {
        return $this->model->create($inputs);
    }
    /**
     * FindOrFail Model and return the instance.
     *
     * @param int $id
     *
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
     *
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
     */
    public function getById($id)
    {
        return $this->model->findOrFail($id);
    }
    /**
     * Update the model in the database.
     *
     * @param $id
     * @param array $inputs
     */
    public function update($id, array $inputs)
    {
        $this->getById($id)->update($inputs);
    }
    /**
     * Delete the model from the database.
     *
     * @param int $id
     *
     * @throws \Exception
     */
    public function destroy($id)
    {
        $this->getById($id)->delete();
    }
}

將以下程式碼新增到/App/Console/Commands/stubs命名為repository.stub

將以下程式碼新增到/App/Console/Commands命名為MakeRepositoryCommand.php

/App/Console/Kernel.php新增以下字串

這樣就可以做Repositories的新增了。

Last updated

Was this helpful?