Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

[WIP] Laravel 5.8 support #362

Merged
merged 28 commits into from Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6b11629
composer require laravel 5.8
tabacitu Feb 27, 2019
f2037cf
bumped tightenco/parental version
tabacitu Feb 27, 2019
a5eb317
Apply fixes from StyleCI
tabacitu Feb 27, 2019
634c244
removed tightenco/parental requirement as its only actually used in p…
tabacitu Feb 27, 2019
853d736
removed jenssegers/date requirement since carbon 2 now offers proper …
tabacitu Feb 27, 2019
2d4f133
Merge branch 'upgrade' of https://github.com/Laravel-Backpack/Base in…
tabacitu Feb 27, 2019
a448f64
removed any trace of tightenco/parental
tabacitu Feb 27, 2019
5d2e4ed
removed unnecessary manual loading of providers and aliases in BaseSe…
tabacitu Feb 27, 2019
e5c5de3
date format is now in ISO format in config file
tabacitu Feb 27, 2019
4b8fe1a
Merge branch 'upgrade' of https://github.com/Laravel-Backpack/Base in…
tabacitu Feb 27, 2019
c34053a
forcing 2.4.9 version of adminlte in order to have bootstrap xss fix
tabacitu Feb 27, 2019
6c825b3
forcing 2.4.9 version of adminlte in order to have bootstrap xss fix
tabacitu Feb 27, 2019
9f77960
bumped adminlte version
tabacitu Feb 27, 2019
aa1a43c
adminlte req
tabacitu Feb 27, 2019
e51db26
added InheritsRelationFromParentModel trait
tabacitu Feb 27, 2019
55d3bad
Merge branch 'upgrade' of https://github.com/Laravel-Backpack/Base in…
tabacitu Feb 27, 2019
671cde2
Apply fixes from StyleCI
tabacitu Feb 27, 2019
3ba4115
bumped adminlte requirement
tabacitu Feb 28, 2019
99f1691
roll back adminlte to previous version
tabacitu Feb 28, 2019
9816aec
re-requiring tightenco/parental
tabacitu Feb 28, 2019
a7b73e2
removed tightenco/parental dependency; AGAIN
tabacitu Feb 28, 2019
f8da670
when publishing backpackuser model only replace the namespace
tabacitu Feb 28, 2019
ff3a092
upgrade bootstrap through CDN
tabacitu Feb 28, 2019
044293a
dropped support for laravel 5.6 and 5.7
tabacitu Feb 28, 2019
b50e130
added jenssegers/date dependency back
tabacitu Mar 1, 2019
f8f43a8
req in the right place
tabacitu Mar 1, 2019
35b2e41
changelog
tabacitu Mar 1, 2019
a7489e6
changelog
tabacitu Mar 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,24 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

-------

## [1.1.0] - 2019-03-01

### Added
- Laravel 5.8 support;

### Fixed
- Bootstrap was forced to upgrade to 3.4.1 by using a CDN, so that everyone gets the new XSS security vulnerability fix, and the upgrade process is smooth;

### Removed
- ```Tightenco\Parental``` dependency; the trait we were using is now included as ```Backpack\Base\app\Models\Traits\InheritsRelationsFromParentModel;```;

**Upgrade guide:**
- Upgrade to Laravel 5.8 or do ```composer require backpack/base:"1.1.*"
- in your ```App\Models\BackpackUser``` instead of ```Tightenco\Parental\HasParent```, please use ```Backpack\Base\app\Models\Traits\InheritsRelationsFromParentModel```; [here's the diff](https://github.com/Laravel-Backpack/Base/pull/362/files#diff-f075b83ebb2b1ef3ba84dec14b395607);
- if you've overwritten ```inc/head.blade.php``` or ```inc/scripts.blade.php```, please make sure you [use the newest version of Bootstrap](https://github.com/Laravel-Backpack/Base/pull/362/files#diff-96ac3ea4d0cb85053acf44e3772eb5f1); they've fixed a security vulnerability (XSS);


----

## [1.0.4] - 2018-12-10

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Expand Up @@ -17,12 +17,11 @@
}
],
"require": {
"almasaeed2010/AdminLTE" : "2.4.*",
"laravel/framework": "5.6.*|5.7.*",
"almasaeed2010/adminlte" : "2.4.*",
"laravel/framework": "5.6.*|5.7.*|5.8.*",
"prologue/alerts": "^0.4.1",
"jenssegers/date": "^3.2",
"creativeorange/gravatar": "~1.0",
"tightenco/parental": "0.5"
"creativeorange/gravatar": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
Expand Down
11 changes: 0 additions & 11 deletions src/BaseServiceProvider.php
Expand Up @@ -175,17 +175,6 @@ public function register()
// register the helper functions
$this->loadHelpers();

// register its dependencies
$this->app->register(\Jenssegers\Date\DateServiceProvider::class);
$this->app->register(\Prologue\Alerts\AlertsServiceProvider::class);
$this->app->register(\Creativeorange\Gravatar\GravatarServiceProvider::class);

// register their aliases
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
$loader->alias('Date', \Jenssegers\Date\Date::class);
$loader->alias('Gravatar', \Creativeorange\Gravatar\Facades\Gravatar::class);

// register the services that are only used for development
if ($this->app->environment() == 'local') {
if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/Console/Commands/PublishBackpackUserModel.php
Expand Up @@ -77,7 +77,7 @@ protected function buildClass($name = false)
*/
protected function makeReplacements(&$stub)
{
$stub = str_replace('Backpack\Base\app\Models', $this->laravel->getNamespace().'Models', $stub);
$stub = str_replace('Backpack\Base\app\Models;', $this->laravel->getNamespace().'Models;', $stub);

if (!$this->files->exists($this->laravel['path'].'/User.php') && $this->files->exists($this->laravel['path'].'/Models/User.php')) {
$stub = str_replace($this->laravel->getNamespace().'User', $this->laravel->getNamespace().'Models\User', $stub);
Expand Down
4 changes: 2 additions & 2 deletions src/app/Models/BackpackUser.php
Expand Up @@ -3,12 +3,12 @@
namespace Backpack\Base\app\Models;

use App\User;
use Backpack\Base\app\Models\Traits\InheritsRelationsFromParentModel;
use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification;
use Tightenco\Parental\HasParentModel;

class BackpackUser extends User
{
use HasParentModel;
use InheritsRelationsFromParentModel;

protected $table = 'users';

Expand Down
92 changes: 92 additions & 0 deletions src/app/Models/Traits/InheritsRelationsFromParentModel.php
@@ -0,0 +1,92 @@
<?php

namespace Backpack\Base\app\Models\Traits;

use Illuminate\Support\Str;
use ReflectionClass;

/**
* This trait helps a child model (ex: BackpackUser) inherit all relationships of its parent model (ex: User).
* Laravel by default doesn't do that, so packages like Backpack\PermissionManager can't see relationships
* on the BackpackUser model, because they haven't been inherited from User.
*
* The code below has been copy-pasted from https://github.com/tightenco/parental on Feb 27th 2019.
* When they provide support for Laravel 5.8, this entire trait could go away (or load their trait).
*/
trait InheritsRelationsFromParentModel
{
public $hasParent = true;

public static function bootHasParent()
{
static::creating(function ($model) {
if ($model->parentHasHasChildrenTrait()) {
$model->forceFill(
[$model->getInheritanceColumn() => $model->classToAlias(get_class($model))]
);
}
});
static::addGlobalScope(function ($query) {
$instance = new static();
if ($instance->parentHasHasChildrenTrait()) {
$query->where($instance->getInheritanceColumn(), $instance->classToAlias(get_class($instance)));
}
});
}

public function parentHasHasChildrenTrait()
{
return $this->hasChildren ?? false;
}

public function getTable()
{
if (!isset($this->table)) {
return str_replace('\\', '', Str::snake(Str::plural(class_basename($this->getParentClass()))));
}

return $this->table;
}

public function getForeignKey()
{
return Str::snake(class_basename($this->getParentClass())).'_'.$this->primaryKey;
}

public function joiningTable($related, $instance = null)
{
$relatedClassName = method_exists((new $related()), 'getClassNameForRelationships')
? (new $related())->getClassNameForRelationships()
: class_basename($related);
$models = [
Str::snake($relatedClassName),
Str::snake($this->getClassNameForRelationships()),
];
sort($models);

return strtolower(implode('_', $models));
}

public function getClassNameForRelationships()
{
return class_basename($this->getParentClass());
}

public function getMorphClass()
{
if ($this->parentHasHasChildrenTrait()) {
$parentClass = $this->getParentClass();

return (new $parentClass())->getMorphClass();
}

return parent::getMorphClass();
}

protected function getParentClass()
{
static $parentClassName;

return $parentClassName ?: $parentClassName = (new ReflectionClass($this))->getParentClass()->getName();
}
}
1 change: 0 additions & 1 deletion src/config/backpack/base.php
Expand Up @@ -32,7 +32,6 @@
// Options: skin-black, skin-blue, skin-purple, skin-red, skin-yellow, skin-green, skin-blue-light, skin-black-light, skin-purple-light, skin-green-light, skin-red-light, skin-yellow-light

// Date & Datetime Format Syntax: https://github.com/jenssegers/date#usage
// (same as Carbon)
'default_date_format' => 'j F Y',
'default_datetime_format' => 'j F Y H:i',

Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/inc/head.blade.php
Expand Up @@ -16,8 +16,8 @@
@stack('before_styles')

<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="{{ asset('vendor/adminlte/') }}/bower_components/bootstrap/dist/css/bootstrap.min.css">
<!-- Bootstrap 3.4.1 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link rel="stylesheet" href="{{ asset('vendor/adminlte/') }}/bower_components/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">

Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/inc/scripts.blade.php
Expand Up @@ -3,8 +3,8 @@
{{-- <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ asset('vendor/adminlte') }}/bower_components/jquery/dist/jquery.min.js"><\/script>')</script> --}}

<!-- Bootstrap 3.3.7 -->
<script src="{{ asset('vendor/adminlte') }}/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Bootstrap 3.4.1 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script src="{{ asset('vendor/adminlte') }}/plugins/pace/pace.min.js"></script>
<script src="{{ asset('vendor/adminlte') }}/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
{{-- <script src="{{ asset('vendor/adminlte') }}/bower_components/fastclick/lib/fastclick.js"></script> --}}
Expand Down