Carbon & Moment.js

    //  check if expired
    Carbon::parse($createdAt)->addSeconds($this->expires)->isPast();


    // diff in seconds
    $then = Carbon::now()->addMinute();
    $now = Carbon::now();

    $then->diffInSeconds($now, false) // -60
    $now->diffInSeconds($then, false) // 60

// parse string let will_end = '2019-02-01 10:00:00'; let then = moment(new Date(will_end)); // diff in seconds let then = moment().add(1, 'minute'); let now = moment(); then.diff(now, 'seconds'); // 60 now.diff(then, 'seconds'); // -60

@blog #php #js

Eloquent


$this->products() ->select('category_id', DB::raw('count(*) as total')) ->groupBy('category_id') ->get(); Task::first(); Task::all(); Task::get(); Task::pluck('body'); Task::where('disabled', 1); Task::selectRaw('year(created_at) year, monthname(created_at) month, count(*) active')->group_by('year', 'month')->get(); Source::leftJoin('site_target_sources', 'site_sources.id', '=', 'site_target_sources.source_id') ->leftJoin('site_targets', 'site_targets.id', '=', 'site_target_sources.target_id') ->where('site_targets.entity_id', $entity->id) ->groupBy('site_sources.id') ->get(['site_sources.*']); ############################# # PRIMARY KEY ############################ public $primaryKey = 'admin_id'; public $increments = false; ############################# # RELADTIONS ############################ public function comments() { return $this->hasMany('App\Comment'); } public function user() { return $this->belongsTo('App\User'); } public function phone() { return $this->hasOne('App\Phone'); } ############################# # SCOPES ############################ // ------------ Task::incomplete(); public static function incomplete(){ return static::where('completed', 0)->get(); } // ------------ Task::incomplete()->where('other', 1)->get(); public function scopeIncomplete($query){ return $query->where('completed', 0); }

laravel #laravel5.4 @blog

Code snippets

Folders should be normal "755" and files, "644"

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Snippets

    // dates
    Carbon::parse($createdAt)->addSeconds($this->expires)->isPast(); // check if expired

    // token
    $token = app('auth.password.broker')->createToken($user); // create token manually


    // optional

    optional($user)->name

laravel #laravel5.4 @blog

Projects

Tags

Capsule Servers

Lost connection to server.