小编Cai*_*aki的帖子

检查Gulp中是否存在文件

我需要检查gulp任务中是否存在文件,我知道我可以使用节点中的某些节点函数,有两个:

fs.exists()fs.existsSync()

问题是在节点文档中,说这些函数将被弃用

javascript node.js gulp

30
推荐指数
1
解决办法
2万
查看次数

Axios/Vue - 防止axios.all()继续执行

在我的应用程序中,我会调用fetchData函数来验证用户身份.如果用户令牌变为无效,应用程序将运行axios.all(),我的拦截器将返回大量错误.

axios.all()第一次出错后如何防止继续运行?并只向用户显示一个通知?

interceptors.js

export default (http, store, router) => {
    http.interceptors.response.use(response => response, (error) => {
        const {response} = error;

        let message = 'Ops. Algo de errado aconteceu...';

        if([401].indexOf(response.status) > -1){
            localforage.removeItem('token');

            router.push({
                name: 'login'
            });

            Vue.notify({
                group: 'panel',
                type: 'error',
                duration: 5000,
                text: response.data.message ? response.data.message : message
            });
        }

        return Promise.reject(error);
    })
}
Run Code Online (Sandbox Code Playgroud)

auth.js

const actions = {
    fetchData({commit, dispatch}) {
        function getChannels() {
            return http.get('channels')
        }

        function getContacts() {
            return http.get('conversations')
        }

        function getEventActions() …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js axios vue-cli

17
推荐指数
1
解决办法
1177
查看次数

Laravel - 可重用的资源控制器

我正在修改我在项目中使用的CMS,最近我决定为默认操作创建一个控制器BaseController,其他所有控制器都将扩展该控制器BaseController.

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    protected $viewFolder = 'admin';

    protected $title;

    protected $model;

    protected $key = 'id';

    protected $files = [];

    public function __construct()
    {
        $this->setVariable('title', $this->title);
    }

    public function index()
    {
        $items = $this->model::paginate();

        $this->setVariable('items', $items);

        return $this->viewRender('index');
    }

    public function create()
    {
        return $this->viewRender('create');
    }

    public function store(ExampleStoreRequestFROMEXAMPLECONTROLLER $request)
    {
        $item = $this->model::create($request->all());

        return redirect()->route($this->viewFolder.'.'.$this->viewType.'.show', $item[$this->key]);
    }

    public function show($id)
    {
        $item = $this->model::where($this->key, $id)->firstOrFail();

        $this->setVariable('item', $item);

        return …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5 laravel-5.6

11
推荐指数
1
解决办法
1134
查看次数

Laravel - 如果用户未经过身份验证,如何重定向到登录

我正在尝试使用__constructor扩展类(AdminController扩展AdminBaseController),但显然它不起作用,我不知道它可以是什么,在这里你可以看到我的两个类:

AdminBaseController.php

class AdminBaseController extends Controller
{
    public function __construct(){
        if (!Auth::user()){
            return view('admin.pages.login.index');
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

AdminController.php

class AdminController extends AdminBaseController
{
    public function __construct(){
        parent::__construct();
    }

    public function index()
    {
        return view('admin.pages.admin.index');
    }

    public function ajuda()
    {
        return view('admin.pages.admin.ajuda');
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑


这是我的admin路线组:

Route::group([
    'prefix' => 'admin',
    'middleware' => 'auth'
], function () {
    Route::get('/', 'Admin\AdminController@index');

    Route::get('login', 'Admin\AuthController@getLogin');
    Route::post('login', 'Admin\AuthController@postLogin');
    Route::get('logout', 'Admin\AuthController@getLogout');

    Route::group(['prefix' => 'configuracoes'], function () {
        Route::get('geral', 'Admin\AdminConfiguracoesController@geral'); …
Run Code Online (Sandbox Code Playgroud)

php authentication laravel laravel-5 laravel-5.1

10
推荐指数
1
解决办法
4万
查看次数

Laravel - 从设置表中设置全局变量

我正试图将我的settings表中的所有设置存储到一个全局变量中,但我现在陷入困境(我不知道下一步是什么),这是我的实际模型和播种机:

model - Settings.php

class Setting extends Model
{
    protected $table = 'settings';

    public $timestamps = false;

    protected $fillable = [
        'name',
        'value',
    ];
}
Run Code Online (Sandbox Code Playgroud)

播种机 - SettingsTableSeeder.php

class SettingsTableSeeder extends Seeder
{
    public function run()
    {

        $settings = [
            ['name' => 'title', 'value' => ''],
            ['name' => 'facebook', 'value' => ''],
            ['name' => 'twitter', 'value' => ''],
            ['name' => 'instagram', 'value' => '']
        ];

        foreach($settings as $setting){
            \App\Setting::create($setting);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何将所有数据存储在设置表中,然后从刀片或任何控制器或视图中进行访问?

编辑


现在,我的问题是,如何从表单更新单个或多个值?

我已经设置了这个:

我的路线:

Route::put('/', …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5.1

10
推荐指数
2
解决办法
1万
查看次数

如何从胡须内的过滤器输出html

我有一个输入(右上角)用户可以搜索的东西,当它的指令长度得到3个字符时,它将显示产品列表并突出显示匹配...

看看我的代码:

HTML

<div id="app">
  <div id="header">
    <div class="right"><input type="text" v-model="message" v-on:keyup="searchStart()" v-on:blur="searchLeave()"/>
      <ul v-if="this.searchInput" class="product-list">
      <li v-for="product in products">
        {{ product.id }} - {{ product.name | highlight }} - {{ product.qtd }}</li></ul>
    </div>
  </div>
  <div id="main">
    <div id="menu">fdfds</div>
    <div id="container">{{ message }}</div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

JS

var search = new Vue({
  el: "#app",
  data: {
    message: "",
    searchInput: false,
    products: [
      {
        id: 1,
        name: "produto 01",
        qtd: 20
      },
      {
        id: 2,
        name: "produto 02",
        qtd: 40
      },
      { …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js

9
推荐指数
1
解决办法
987
查看次数

将多个参数传递给刀片指令

我正在尝试创建一个刀片指令,以突出显示将从我的搜索查询返回的一些单词.

这是我的刀片指令:

class AppServiceProvider extends ServiceProvider

{
    public function boot()
    {
        Blade::directive('highlight', function($expression, $string){

            $expressionValues = preg_split('/\s+/', $expression);

            foreach ($expressionValues as $value) {
                $string = str_replace($value, "<b>".$value."</b>", $string);
            }

            return "<?php echo {$string}; ?>";
        });
    }

    public function register()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我用这样的方式调用刀片:

@highlight('ho', 'house')
Run Code Online (Sandbox Code Playgroud)

但是,这个错误跟随着我:

Missing argument 2 for App\Providers\AppServiceProvider::App\Providers\{closure}()
Run Code Online (Sandbox Code Playgroud)

怎么解决?

php laravel blade laravel-blade laravel-5.3

8
推荐指数
4
解决办法
5898
查看次数

Hairline gaps between items in isotope-packery on window resize

我的同位素包装布局存在一个小问题,在某些窗口尺寸的某些项目之间出现非常薄的1px或更少的线条.有没有办法消除这种发际差距?

示例:http://i.imgur.com/6jkqhZw.png(查看第3项和第4项)

我在这里看一下JSFiddle:http://jsfiddle.net/drawcard/akw6m9x1/ (调整小提琴"窗口",这样你就可以看到空白)

// external js:
// http://isotope.metafizzy.co/beta/isotope.pkgd.js

//packery js (no need to copy this over if you have it included)
/*!
 * Packery layout mode PACKAGED v1.1.0
 * sub-classes Packery
 * http://packery.metafizzy.co
 */

!function(a){function b(a){return new RegExp("(^|\\s+)"+a+"(\\s+|$)")}function c(a,b){var c=d(a,b)?f:e;c(a,b)}var d,e,f;"classList"in document.documentElement?(d=function(a,b){return a.classList.contains(b)},e=function(a,b){a.classList.add(b)},f=function(a,b){a.classList.remove(b)}):(d=function(a,c){return b(c).test(a.className)},e=function(a,b){d(a,b)||(a.className=a.className+" "+b)},f=function(a,c){a.className=a.className.replace(b(c)," ")});var g={hasClass:d,addClass:e,removeClass:f,toggleClass:c,has:d,add:e,remove:f,toggle:c};"function"==typeof define&&define.amd?define("classie/classie",g):"object"==typeof exports?module.exports=g:a.classie=g}(window),function(a){function b(){function a(b){for(var c in a.defaults)this[c]=a.defaults[c];for(c in b)this[c]=b[c]}return c.Rect=a,a.defaults={x:0,y:0,width:0,height:0},a.prototype.contains=function(a){var b=a.width||0,c=a.height||0;return this.x<=a.x&&this.y<=a.y&&this.x+this.width>=a.x+b&&this.y+this.height>=a.y+c},a.prototype.overlaps=function(a){var b=this.x+this.width,c=this.y+this.height,d=a.x+a.width,e=a.y+a.height;return this.x<d&&b>a.x&&this.y<e&&c>a.y},a.prototype.getMaximalFreeRects=function(b){if(!this.overlaps(b))return!1;var c,d=[],e=this.x+this.width,f=this.y+this.height,g=b.x+b.width,h=b.y+b.height;return this.y<b.y&&(c=new a({x:this.x,y:this.y,width:this.width,height:b.y-this.y}),d.push(c)),e>g&&(c=new a({x:g,y:this.y,width:e-g,height:this.height}),d.push(c)),f>h&&(c=new a({x:this.x,y:h,width:this.width,height:f-h}),d.push(c)),this.x<b.x&&(c=new a({x:this.x,y:this.y,width:b.x-this.x,height:this.height}),d.push(c)),d},a.prototype.canFit=function(a){return this.width>=a.width&&this.height>=a.height},a}var c=a.Packery=function(){};"function"==typeof define&&define.amd?define("packery/js/rect",b):"object"==typeof exports?module.exports=b():(a.Packery=a.Packery||{},a.Packery.Rect=b())}(window),function(a){function b(a){function …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery jquery-isotope

7
推荐指数
1
解决办法
1436
查看次数

如何检查Laravel Blade中的当前路线是否与模式匹配?

我正在检查我的刀片模板中的路由,li使用以下代码将活动类添加到菜单中的特定类:

<ul>
    <li class="{{ Request::is('*/sobre') || Request::is('*') ? "active" : "" }}">
        <a href="{{ Route::getCurrentRoute()->parameters()['domain'] . "/sobre" }}">Sobre o salão</a>
    </li>
    <li class="{{ Request::is('*/servicos') ? "active" : "" }}">
        <a href="{{ Route::getCurrentRoute()->parameters()['domain'] . "/servicos" }}">Serviços</a>
    </li>
    <li class="{{ Request::is('*/avaliacoes') ? "active" : "" }}">
        <a href="{{ Route::getCurrentRoute()->parameters()['domain'] . "/avaliacoes" }}">Avaliações</a>
    </li>
    <li class="{{ Request::is('*/galeria') ? "active" : "" }}">
        <a href="{{ Route::getCurrentRoute()->parameters()['domain'] . "/galeria" }}">Fotos</a>
    </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

这些是路线:

Route::group(['prefix' => '{domain}', 'middleware'=>'salao'], function () {
    Route::get('/', 'Frontend\FrontendSalaoController@sobre');
    Route::get('sobre', …
Run Code Online (Sandbox Code Playgroud)

regex laravel laravel-5 laravel-blade

6
推荐指数
1
解决办法
3033
查看次数

Laravel - 在Middleware Auth上包含资产

在我的应用程序内部,存在一个名为的路由组admin,该组内的任何路由都会调用两个资源:public/css/admin.css并且public/js/admin.js,但是任何未经身份验证的用户都可以访问这些文件.如何在Auth Middleware中包含这些文件?

我的管理路线:

Route::group(['prefix' => 'admin', 'middleware' => ['auth']], function () {
    Route::get('/', 'Admin\IndexController@index')->name('panel');

    Route::group(['prefix' => 'users'], function() {});

    Route::group(['prefix' => 'settings'], function() {});

    Route::fallback('Admin\ExceptionController@exception');
});
Run Code Online (Sandbox Code Playgroud)

我的资源链接:

http://localhost:3000/css/admin.css
http://localhost:3000/js/admin.js
Run Code Online (Sandbox Code Playgroud)

我的资源链接应该是:

http://localhost:3000/admin/css/admin.css
http://localhost:3000/admin/js/admin.js
Run Code Online (Sandbox Code Playgroud)

如果我只需要创建一个文件夹admin里面public的文件夹我刚刚得到一个403错误...

我能做些什么呢?

php laravel laravel-5.5

6
推荐指数
2
解决办法
1225
查看次数