[WIP] config Datatables/Webpack/Yajra
This commit is contained in:
89
app/Datatables/FamiliesDataTable.php
Normal file
89
app/Datatables/FamiliesDataTable.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
|
||||
use Yajra\DataTables\Html\Button;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use Yajra\DataTables\Html\Editor\Editor;
|
||||
use Yajra\DataTables\Html\Editor\Fields;
|
||||
use Yajra\DataTables\Services\DataTable;
|
||||
|
||||
use App\Models\Shop\Family;
|
||||
|
||||
class FamiliesDataTable extends DataTable
|
||||
{
|
||||
/**
|
||||
* Build DataTable class.
|
||||
*
|
||||
* @param mixed $query Results from query() method.
|
||||
* @return \Yajra\DataTables\DataTableAbstract
|
||||
*/
|
||||
public function dataTable($query)
|
||||
{
|
||||
return datatables()
|
||||
->eloquent($query)
|
||||
->addColumn('action', '<a href="{{$id}}"><i class="fa fa-edit"></i></a>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query source of dataTable.
|
||||
*
|
||||
* @param \App\Family $model
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function query(Family $model)
|
||||
{
|
||||
return $model->newQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional method if you want to use html builder.
|
||||
*
|
||||
* @return \Yajra\DataTables\Html\Builder
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return $this->builder()
|
||||
->setTableId('families-table')
|
||||
->columns($this->getColumns())
|
||||
->minifiedAjax()
|
||||
->dom('Bfrtip')
|
||||
->orderBy(1)
|
||||
->buttons(
|
||||
Button::make('create'),
|
||||
Button::make('export'),
|
||||
Button::make('print'),
|
||||
Button::make('reset'),
|
||||
Button::make('reload')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get columns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('alias'),
|
||||
Column::make('latin'),
|
||||
Column::computed('action')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
->width(60)
|
||||
->addClass('text-center'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename for export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function filename()
|
||||
{
|
||||
return 'Families_' . date('YmdHis');
|
||||
}
|
||||
}
|
||||
29
app/Http/Controllers/Admin/HomeController.php
Normal file
29
app/Http/Controllers/Admin/HomeController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// return redirect('dashboard');
|
||||
}
|
||||
}
|
||||
52
app/Http/Controllers/Shop/Admin/FamilyController.php
Normal file
52
app/Http/Controllers/Shop/Admin/FamilyController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Families;
|
||||
use App\DataTables\FamiliesDataTable;
|
||||
|
||||
class FamilyController extends Controller
|
||||
{
|
||||
|
||||
public function index(FamiliesDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Shop.Admin.Families.list');
|
||||
}
|
||||
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Families::getTables($request->all());
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
return view('Shop.Admin.Families.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Families::store($request);
|
||||
return redirect()->route('Shop.Admin.Families.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data = Families::get($id);
|
||||
return view('Shop.Admin.Families.view', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Families::get($id);
|
||||
return view('Shop.Admin.Families.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Families::destroy($id);
|
||||
}
|
||||
}
|
||||
55
app/Http/Controllers/Shop/Admin/GenreController.php
Normal file
55
app/Http/Controllers/Shop/Admin/GenreController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Genres;
|
||||
|
||||
class GenreController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
if ($request->ajax()) {
|
||||
return self::getDatatable($request);
|
||||
} else {
|
||||
$data = [];
|
||||
return view('Admin.Shop.Genres.list', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Genres::getTables($request->all());
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
return view('Admin.Shop.Genres.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Genres::store($request);
|
||||
return redirect()->route('Admin.Shop.Genres.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data = Genres::get($id);
|
||||
return view('Admin.Shop.Genres.view', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Genres::get($id);
|
||||
return view('Admin.Shop.Genres.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Genres::destroy($id);
|
||||
}
|
||||
}
|
||||
101
app/Http/Controllers/Shop/Admin/SpecieController.php
Normal file
101
app/Http/Controllers/Shop/Admin/SpecieController.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Species;
|
||||
|
||||
class SpecieController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
if ($request->ajax()) {
|
||||
return self::getDatatable($request);
|
||||
} else {
|
||||
$data = [];
|
||||
return view('Shop.Admin.Species.list', $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Species::getDatatable($request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
return view('Shop.Admin.Species.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Species::store($request);
|
||||
return redirect()->route('Shop.Admin.Species.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Customer $customer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data = Species::get($id);
|
||||
return view('Shop.Admin.Species.view', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Customer $customer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Species::get($id);
|
||||
return view('Shop.Admin.Species.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Customer $customer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Customer $customer
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
return Species::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,26 @@ class Shop
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add('Commerce', [ 'permission' => 'backend', 'icon' => 'cog' ])
|
||||
$menu->add('Commerce', [ 'permission' => 'backend', 'icon' => 'shopping-basket' ])
|
||||
->id('shop')
|
||||
->activeIfRoute('shop')
|
||||
|
||||
->order(1);
|
||||
|
||||
$menu->addTo('shop', 'Familles', [ 'route' => 'Shop.Admin.Families.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Families.index'])->order(1);
|
||||
$menu->addTo('shop', 'Genres', [ 'route' => 'Shop.Admin.Genres.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Genres.index'])->order(2);
|
||||
$menu->addTo('shop', 'Espèces', [ 'route' => 'Shop.Admin.Species.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Species.index'])->order(3);
|
||||
|
||||
$menu->addTo('shop', 'Categories', [ 'route' => 'Shop.Admin.Sections.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Sections.index'])->order(1);
|
||||
->activeIfRoute(['Shop.Admin.Sections.index'])->order(4);
|
||||
$menu->addTo('shop', 'Produits', [ 'route' => 'Shop.Admin.Products.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Products.index'])->order(2);
|
||||
->activeIfRoute(['Shop.Admin.Products.index'])->order(5);
|
||||
$menu->addTo('shop', 'Commandes', [ 'route' => 'Shop.Admin.Orders.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Orders.index'])->order(3);
|
||||
->activeIfRoute(['Shop.Admin.Orders.index'])->order(6);
|
||||
$menu->addTo('shop', 'Factures', [ 'route' => 'Shop.Admin.Invoices.index', 'permission' => 'backend' ])
|
||||
->activeIfRoute(['Shop.Admin.Invoices.index'])->order(4);
|
||||
->activeIfRoute(['Shop.Admin.Invoices.index'])->order(7);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Modules;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Family extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Modules;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Species extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
}
|
||||
16
app/Models/Shop/Family.php
Normal file
16
app/Models/Shop/Family.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Family extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_product_families';
|
||||
|
||||
public function genres()
|
||||
{
|
||||
return $this->hasMany('App\Models\Shop\Genre');
|
||||
}
|
||||
}
|
||||
17
app/Models/Shop/Genre.php
Normal file
17
app/Models/Shop/Genre.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Genres extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_product_genres';
|
||||
|
||||
public function family()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Family');
|
||||
}
|
||||
|
||||
}
|
||||
16
app/Models/Shop/Specie.php
Normal file
16
app/Models/Shop/Specie.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Species extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_product_species';
|
||||
|
||||
public function Genre()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shop\Family');
|
||||
}
|
||||
}
|
||||
54
app/Repositories/Families.php
Normal file
54
app/Repositories/Families.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Family;
|
||||
|
||||
class Families
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Family::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Family::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Family::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Family::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Family::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Family::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
54
app/Repositories/Genres.php
Normal file
54
app/Repositories/Genres.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Genre;
|
||||
|
||||
class Genres
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Genre::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Genre::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Genre::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Genre::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Genre::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Genre::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -15,203 +15,40 @@ class Products
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Product::with(['sections'])->orderBy('name');
|
||||
$model = Product::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function select_all()
|
||||
public static function getAll()
|
||||
{
|
||||
return Product::select('id','name','active')->orderBy('name','asc')->get()->toArray();
|
||||
return Product::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
public static function get($id)
|
||||
{
|
||||
return Product::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getId($Product = false)
|
||||
{
|
||||
$Product = self::get($Product);
|
||||
return $Product ? $Product->id : false;
|
||||
}
|
||||
|
||||
public static function get($Product = false)
|
||||
{
|
||||
$website = self::getWebsite($Product);
|
||||
return $website ? Product::byWebsite($website->id)->first() : false;
|
||||
return Product::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
if (!$id) {
|
||||
$Product_id = self::create($data);
|
||||
} else {
|
||||
$Product_id = self::update($data);
|
||||
}
|
||||
|
||||
ApplicationProducts::associate($Product_id, $data['applications']);
|
||||
|
||||
return $Product_id;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$slug = Str::slug($data['slug'],'-');
|
||||
$url = $slug . '.' . Partners::getDomain();
|
||||
$website = Websites::create($url);
|
||||
$item = [];
|
||||
$item['website_id'] = $website->id;
|
||||
$item['name'] = $data['name'];
|
||||
$item['slug'] = $slug;
|
||||
$item['repository'] = $slug;
|
||||
$item['session_name'] = $slug . '_sess';
|
||||
$item['logo_image'] = 'logo.png';
|
||||
$item['background_image'] = 'login-background.jpg';
|
||||
$item['custom_css'] = 'Product.css';
|
||||
$item['active'] = true;
|
||||
$Product = Product::create($item);
|
||||
|
||||
$DB_system = Partners::getDBName();
|
||||
$sql = "GRANT SELECT ON `$DB_system`.* TO '" . $website->uuid . "'@localhost";
|
||||
DB::connection('system')->statement($sql);
|
||||
// GRANT SELECT ON `legstack`.* TO '828656d3463e45c0a33e9cc8b5c2f265'@'127.0.0.1';
|
||||
return $Product->id;
|
||||
return Product::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
// TODO
|
||||
return Product::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
$Product = Product::find($id);
|
||||
|
||||
return Product::destroy($id);
|
||||
}
|
||||
|
||||
public static function getPublicPath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getLocalPath() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getPrivatePath renvoie le chemin complet du repertoire du tenant ]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getPrivatePath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getPrivateDir($repository, $Product);
|
||||
}
|
||||
|
||||
public static function getPrivateDir($repository = false, $Product = false)
|
||||
{
|
||||
return self::getLocalDir() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getRelativePath renvoie le chemin relatif au storage ]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getRelativePath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getTenancyRoot() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getPath renvoie le chemin relatif à la tenancy root]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getPath($repository = false, $Product = false)
|
||||
{
|
||||
$path = '/'. self::getSlug($Product);
|
||||
$path .= $repository ? $repository : '';
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* [getStorage revoie le storage du tenant (local, S3, ...)]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getStorage()
|
||||
{
|
||||
return Storage::disk('tenant');
|
||||
}
|
||||
|
||||
public static function getDirectory()
|
||||
{
|
||||
return app(\Hyn\Tenancy\Website\Directory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getLocalDir renvoie le chemin complet vers la tenancy sur le disque]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getLocalDir()
|
||||
{
|
||||
return storage_path('app' . self::getTenancyRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* [getLocalPath revnoie le chemin public vers la tenancy publique]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getLocalPath()
|
||||
{
|
||||
return '/storage' . self::getTenancyRoot();
|
||||
}
|
||||
|
||||
public static function getSlug($Product = false)
|
||||
{
|
||||
if ($Product) {
|
||||
return $Product;
|
||||
}
|
||||
|
||||
$website = self::getWebsite();
|
||||
if ($website) {
|
||||
return($website->uuid);
|
||||
}
|
||||
|
||||
/*
|
||||
// regarde si le Product existe et qu'il possède au moins une licence valide pour une des applications
|
||||
$host = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : 'legtech.legtech';
|
||||
$url_hostname = explode(".", $host); // décompose l'url de base
|
||||
$slug = $url_hostname[0];
|
||||
if ($slug == 'legstack') {
|
||||
$slug = 'legtech';
|
||||
}
|
||||
return $slug;
|
||||
*/
|
||||
}
|
||||
|
||||
// récupère les informations de connexion à la base du Product
|
||||
public static function getDatabaseEnvironment($Product_id)
|
||||
{
|
||||
return Product::byId($Product_id)->first()->toArray();
|
||||
}
|
||||
|
||||
public static function isProduct()
|
||||
{
|
||||
$website = self::getWebsite();
|
||||
$is_Product = $website ? true : false;
|
||||
return $is_Product;
|
||||
}
|
||||
|
||||
public static function getWebsite()
|
||||
{
|
||||
return \Hyn\Tenancy\Facades\TenancyFacade::website();
|
||||
}
|
||||
|
||||
public static function getWebsiteByProduct($id)
|
||||
{
|
||||
$Product = Product::find($id);
|
||||
return Website::find($Product->website_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
54
app/Repositories/Species.php
Normal file
54
app/Repositories/Species.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Specie;
|
||||
|
||||
class Species
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Specie::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Specie::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Specie::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Specie::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Specie::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Specie::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
225
app/User.php
Normal file
225
app/User.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Yadahan\AuthenticationLog\AuthenticationLogable;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Mpociot\Teamwork\Traits\UserHasTeams;
|
||||
use Sebastienheyd\Boilerplate\Notifications\NewUser as NewUserNotification;
|
||||
use Sebastienheyd\Boilerplate\Notifications\ResetPassword as ResetPasswordNotification;
|
||||
|
||||
/**
|
||||
* Sebastienheyd\Boilerplate\Models\User.
|
||||
*
|
||||
* @property int $id
|
||||
* @property bool $active
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property string $remember_token
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property string $deleted_at
|
||||
* @property string $last_login
|
||||
* @property-read string|false $avatar_path
|
||||
* @property-read string $avatar_url
|
||||
* @property-read mixed $name
|
||||
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Sebastienheyd\Boilerplate\Models\Permission[] $permissions
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Sebastienheyd\Boilerplate\Models\Role[] $roles
|
||||
*
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereActive($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereEmail($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereFirstName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereLastLogin($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereLastName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User wherePassword($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereRememberToken($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereRoleIs($role = '')
|
||||
* @method static \Illuminate\Database\Query\Builder|\Sebastienheyd\Boilerplate\Models\User whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
use LaratrustUserTrait;
|
||||
use SoftDeletes;
|
||||
use UserHasTeams;
|
||||
use AuthenticationLogable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['active', 'last_name', 'first_name', 'email', 'password', 'remember_token', 'last_login'];
|
||||
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function teams()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Core\Auth\Team', 'App\Models\Core\Auth\TeamUser', 'user_id', 'id', 'id', 'team_id');
|
||||
}
|
||||
|
||||
public function scopeByTeam($query, $id)
|
||||
{
|
||||
return $query->whereHas('teams', function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByUniqueTeam($query)
|
||||
{
|
||||
return $query->has('teams', '=', 1);
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('active', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the password reset notification.
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new ResetPasswordNotification($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification when a new user is created.
|
||||
*
|
||||
* @param string $token
|
||||
*/
|
||||
public function sendNewUserNotification($token)
|
||||
{
|
||||
$this->notify(new NewUserNotification($token, $this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return last name in uppercase by default.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastNameAttribute($value)
|
||||
{
|
||||
return mb_strtoupper($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return first name with first char of every word in uppercase.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstNameAttribute($value)
|
||||
{
|
||||
return mb_convert_case($value, MB_CASE_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a concatenation of first name and last_name if field name does not exists.
|
||||
*
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $this->first_name.' '.$this->last_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return last login date formatted.
|
||||
*
|
||||
* @param string $format
|
||||
* @param string $default
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function getLastLogin($format = 'YYYY-MM-DD HH:mm:ss', $default = '')
|
||||
{
|
||||
if ($this->last_login === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return Carbon::createFromTimeString($this->last_login)->isoFormat($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return role list as a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRolesList()
|
||||
{
|
||||
$res = [];
|
||||
foreach ($this->roles as $role) {
|
||||
$res[] = __($role->display_name);
|
||||
}
|
||||
if (empty($res)) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
return implode(', ', $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current user has an avatar.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function getAvatarPathAttribute()
|
||||
{
|
||||
return public_path('images/avatars/'.md5($this->id.$this->email).'.jpg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current user avatar uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAvatarUrlAttribute()
|
||||
{
|
||||
if (is_file($this->avatar_path)) {
|
||||
$ts = filemtime($this->avatar_path);
|
||||
|
||||
return asset('images/avatars/'.md5($this->id.$this->email).'.jpg?t='.$ts);
|
||||
}
|
||||
|
||||
return asset('/assets/vendor/boilerplate/images/default-user.png');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user